i have this error when i want to call my method update, dispite i have no show mrthid in my UsersGestionController
Thank you for help
UserGestionController.php :
public function utilisateurlist()
{
$usersList = User::orderBy('id_role', 'desc')->take(50)->get();
return view('events.ListeUtilisateur', ['usersList' => $usersList]);
}
public function update(Request $request)
{
$id=$request->id;
$name=$request->name;
$email=$request->email;
$id_role=$request->id_role;
$update = [
'id'=> $id,
'name'=> $name,
'email'=> $email,
'id_role'=> $id_role,
];
User:where('id',$request->id)->update($update);
return redirect()->route('userlist');
}
web.php :
Route::get('/userslist', function () {
return view('users.ListeUtilisateur');
});
Route::resource('events', EventsController::class);
Route::resource('users', UsersGestionController::class);
Route::middleware(['auth:sanctum', 'verified'])->get(
'/userslist',
[App\Http\Controllers\UsersGestionController::class, 'utilisateurlist'])->name('userslist');
Route::get('page1', function () { return view("page1"); })->middleware('auth');
Route::post('update',[App\Http\Controllers\UsersGestionController::class,'update'])->name('update');
list.blade.php :
<a class="btn btn-warning" href="{{route('users.update',$users->id)}}">Update</a>
CodePudding user response:
Do you have use App\Models\User
on top of your controller?
And are the colomns marked as fillable in the model?
This might work:
$user = User::find($id);
$user>name = $name:
$user->email = $email;
$user->id_role = $id_role;
$user->save();
return redirect('/userslist');
CodePudding user response:
you need to import correctly your controller on web.php routes and to change your route like :
use App\Http\Controllers\UsersGestionController;
Route::post('update',[UsersGestionController::class,'update'])->name('update');