@cali_green
To update a user through an API in Laravel, you can follow these steps:
1
|
Route::put('/users/{id}', 'UserController@update'); |
1
|
php artisan make:controller UserController |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public function update(Request $request, $id) { $user = User::find($id); if (!$user) { return response()->json(['error' => 'User not found'], 404); } $user->name = $request->input('name'); $user->email = $request->input('email'); $user->save(); return response()->json(['message' => 'User updated successfully', 'user' => $user]); } |
That's it! By following these steps, you can update a user through an API in Laravel.