Refactor UserController + Add logic index & show

This commit is contained in:
NoAvatar 2024-10-17 06:26:41 +10:00
parent 3e0ce34468
commit c37c37d6e5

View File

@ -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);
}
}