File tree Expand file tree Collapse file tree 8 files changed +25
-18
lines changed Expand file tree Collapse file tree 8 files changed +25
-18
lines changed Original file line number Diff line number Diff line change 33namespace App \Http \Controllers \Personal \Comment ;
44
55use App \Http \Controllers \Controller ;
6+ use Illuminate \Contracts \Auth \Authenticatable ;
67use Illuminate \Contracts \View \Factory as ViewFactory ;
78
89class IndexController extends Controller
910{
10- public function __invoke (ViewFactory $ view_factory )
11+ public function __invoke (ViewFactory $ view_factory, Authenticatable $ user )
1112 {
1213 /** @phpstan-ignore-next-line */
13- $ comments = auth ()-> user () ->comments ;
14+ $ comments = $ user ->comments ;
1415
1516 return $ view_factory ->make ('personal.comment.index ' , ['comments ' => $ comments ]);
1617 }
Original file line number Diff line number Diff line change 44
55use App \Http \Controllers \Controller ;
66use App \Models \Post ;
7+ use Illuminate \Contracts \Auth \Authenticatable ;
78
89class DeleteController extends Controller
910{
10- public function __invoke (Post $ post )
11+ public function __invoke (Post $ post, Authenticatable $ user )
1112 {
1213 /** @phpstan-ignore-next-line */
13- auth ()-> user () ->likedPosts ()->detach ($ post ->id );
14+ $ user ->likedPosts ()->detach ($ post ->id );
1415
1516 return redirect ()->route ('personal.liked.index ' );
1617 }
Original file line number Diff line number Diff line change 33namespace App \Http \Controllers \Personal \Liked ;
44
55use App \Http \Controllers \Controller ;
6+ use Illuminate \Contracts \Auth \Authenticatable ;
67use Illuminate \Contracts \View \Factory as ViewFactory ;
78
89class IndexController extends Controller
910{
10- public function __invoke (ViewFactory $ view_factory )
11+ public function __invoke (ViewFactory $ view_factory, Authenticatable $ user )
1112 {
1213 /** @phpstan-ignore-next-line */
13- $ posts = auth ()-> user () ->likedPosts ;
14+ $ posts = $ user ->likedPosts ;
1415
1516 return $ view_factory ->make ('personal.liked.index ' , ['posts ' => $ posts ]);
1617 }
Original file line number Diff line number Diff line change 33namespace App \Http \Controllers \Personal \Main ;
44
55use App \Http \Controllers \Controller ;
6+ use Illuminate \Contracts \Auth \Authenticatable ;
67use Illuminate \Contracts \View \Factory as ViewFactory ;
78
89class IndexController extends Controller
910{
10- public function __invoke (ViewFactory $ view_factory )
11+ public function __invoke (ViewFactory $ view_factory, Authenticatable $ user )
1112 {
1213 /** @phpstan-ignore-next-line */
13- $ data ['countComments ' ] = count (auth ()-> user () ->comments );
14+ $ data ['countComments ' ] = count ($ user ->comments );
1415 /** @phpstan-ignore-next-line */
15- $ data ['countLiked ' ] = count (auth ()-> user () ->likedPosts );
16+ $ data ['countLiked ' ] = count ($ user ->likedPosts );
1617
1718 return $ view_factory ->make ('personal.main.index ' , ['data ' => $ data ]);
1819 }
Original file line number Diff line number Diff line change 66use App \Http \Requests \Post \Comment \StoreRequest ;
77use App \Models \Comment ;
88use App \Models \Post ;
9+ use Illuminate \Contracts \Auth \Authenticatable ;
910
1011class StoreController extends Controller
1112{
12- public function __invoke (StoreRequest $ request , Post $ post )
13+ public function __invoke (StoreRequest $ request , Post $ post, Authenticatable $ user )
1314 {
1415 $ data = $ request ->validated ();
1516 $ data ['post_id ' ] = $ post ->id ;
16- /** @phpstan-ignore-next-line */
17- $ data ['user_id ' ] = auth ()-> user () ->id ;
17+ /** @phpstan-ignore-next-line */
18+ $ data ['user_id ' ] = $ user ->id ;
1819 /** @phpstan-ignore-next-line */
1920 Comment::create ($ data );
2021
Original file line number Diff line number Diff line change 44
55use App \Http \Controllers \Controller ;
66use App \Models \Post ;
7+ use Illuminate \Contracts \Auth \Authenticatable ;
78
89class StoreController extends Controller
910{
10- public function __invoke (Post $ post )
11+ public function __invoke (Post $ post, Authenticatable $ user )
1112 {
1213 /** @phpstan-ignore-next-line */
13- auth ()-> user () ->likedPosts ()->toggle ($ post ->id );
14+ $ user ->likedPosts ()->toggle ($ post ->id );
1415
1516 return redirect ()->back ();
1617 }
Original file line number Diff line number Diff line change @@ -15,8 +15,9 @@ class AdminMiddleware
1515 */
1616 public function handle (Request $ request , Closure $ next ): Response
1717 {
18- /** @phpstan-ignore-next-line */
19- if (auth ()->user ()->isReader ()) {
18+ $ user = $ request ->user ();
19+
20+ if (! $ user || ! $ user ->isAdministrator ()) {
2021 abort (404 );
2122 }
2223
Original file line number Diff line number Diff line change 4848Route::prefix ('post ' )->namespace ('' )->group (function () {
4949 Route::get ('/{post} ' , [PostController::class, 'show ' ])->name ('post.show ' );
5050
51- Route::prefix ('{post}/comments ' )->group (function () {
51+ Route::prefix ('{post}/comments ' )->middleware ( ' auth ' )-> group (function () {
5252 Route::post ('/ ' , 'App\Http\Controllers\Post\Comment\StoreController ' )->name ('post.comments.store ' );
5353 });
54- Route::prefix ('{post}/likes ' )->group (function () {
54+ Route::prefix ('{post}/likes ' )->middleware ( ' auth ' )-> group (function () {
5555 Route::post ('/ ' , 'App\Http\Controllers\Post\Like\StoreController ' )->name ('post.likes.store ' );
5656 });
5757});
You can’t perform that action at this time.
0 commit comments