File tree Expand file tree Collapse file tree 3 files changed +84
-14
lines changed Expand file tree Collapse file tree 3 files changed +84
-14
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Http \Controllers ;
4+
5+ use App \Http \Resources \UserResource ;
6+ use Illuminate \Support \Facades \Auth ;
7+
8+ class AuthController extends Controller
9+ {
10+ public function __invoke ()
11+ {
12+ return new UserResource (Auth::user ());
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Http \Controllers ;
4+
5+ use App \Models \User ;
6+ use Illuminate \Http \Request ;
7+ use App \Http \Resources \UserResource ;
8+
9+ class UserController extends Controller
10+ {
11+ /**
12+ * Display a listing of the resource.
13+ *
14+ * @return \Illuminate\Http\Response
15+ */
16+ public function index ()
17+ {
18+ return UserResource::collection (User::paginate ());
19+ }
20+
21+ /**
22+ * Store a newly created resource in storage.
23+ *
24+ * @param \Illuminate\Http\Request $request
25+ * @return \Illuminate\Http\Response
26+ */
27+ public function store (Request $ request )
28+ {
29+ //
30+ }
31+
32+ /**
33+ * Display the specified resource.
34+ *
35+ * @param int $id
36+ * @return \Illuminate\Http\Response
37+ */
38+ public function show (User $ user )
39+ {
40+ return new UserResource ($ user );
41+ }
42+
43+ /**
44+ * Update the specified resource in storage.
45+ *
46+ * @param \Illuminate\Http\Request $request
47+ * @param int $id
48+ * @return \Illuminate\Http\Response
49+ */
50+ public function update (Request $ request , $ id )
51+ {
52+ //
53+ }
54+
55+ /**
56+ * Remove the specified resource from storage.
57+ *
58+ * @param int $id
59+ * @return \Illuminate\Http\Response
60+ */
61+ public function destroy ($ id )
62+ {
63+ //
64+ }
65+ }
Original file line number Diff line number Diff line change 11<?php
22
3- use Illuminate \Support \Facades \Auth ;
43use Illuminate \Support \Facades \Route ;
4+ use App \Http \Controllers \AuthController ;
5+ use App \Http \Controllers \UserController ;
56use App \Http \Controllers \TokenController ;
67use App \Http \Controllers \AvatarController ;
7- use App \Http \Resources \UserResource ;
8- use App \Models \User ;
98
109/*
1110|--------------------------------------------------------------------------
2120Route::post ('/sanctum/token ' , TokenController::class);
2221
2322Route::middleware (['auth:sanctum ' ])->group (function () {
24- Route::get ('/users/auth ' , function () {
25- return new UserResource (Auth::user ());
26- });
27-
28- Route::get ('/users/{id} ' , function ($ id ) {
29- return new UserResource (User::findOrFail ($ id ));
30- });
31-
32- Route::get ('/users ' , function () {
33- return UserResource::collection (User::paginate ());
34- });
23+ Route::get ('/users/auth ' , AuthController::class);
24+ Route::get ('/users/{user} ' , [UserController::class, 'show ' ]);
25+ Route::get ('/users ' , [UserController::class, 'index ' ]);
3526
3627 Route::post ('/users/auth/avatar ' , [AvatarController::class, 'store ' ]);
3728});
You can’t perform that action at this time.
0 commit comments