From c37c37d6e54279db1ce7befe005f42fb9f50f343 Mon Sep 17 00:00:00 2001 From: NoAvatar Date: Thu, 17 Oct 2024 06:26:41 +1000 Subject: [PATCH] Refactor UserController + Add logic index & show --- app/Http/Controllers/UserController.php | 42 +++++++++---------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index a11b726..f179855 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -2,52 +2,40 @@ namespace App\Http\Controllers; +use App\Models\User; use Illuminate\Http\Request; class UserController extends Controller { - /** - * Display a listing of the resource. - */ + // GET /user public function index() { - // - return response("Get all users"); + return response(User::all()); } - /** - * Store a newly created resource in storage. - */ - public function store(Request $request) - { - // - return response("User store with data: " . $request->json()); - } - - /** - * Display the specified resource. - */ + // GET /user/{id} public function show(string $id) { - // - return response("User with id " . $id); + $user = User::query()->findOrFail('id', $id); + + return response($user); } - /** - * Update the specified resource in storage. - */ + // POST /user + public function store(Request $request) + { + return response("Create user"); + } + + // PUT /user/{id} public function update(Request $request, string $id) { - // return response("Update user " . $id); } - /** - * Remove the specified resource from storage. - */ + // DELETE /user/{id} public function destroy(string $id) { - // return response("Destroy user " . $id); } }