The submit form which allows admin to change the role of user or staff, error shows Missing required parameter for [Route: updateRolePermission] [URI: admin/edit-role-permission/{id}] [Missing parameter: id]
I have fighting with this issues for many hours, everyone can help thanks!!!!!
<form action="{{ route('updateRolePermission'), ['id' =>$user->id] }}" method="POST">
@csrf
<select name="roles">
<option value="user">User</option>
<option value="staff">Staff</option>
</select>
<input type="submit">
</form>
Route::group(['prefix'=>'admin', 'middleware'=>['isAdmin','auth']], function(){
Route::get('dashboard', [AdminController::class, 'index'])->name('admin.dashboard');
Route::get('role-permission', [AdminController::class, 'rolePermission'])->name('admin.rolePermission');
//it doesnt work!!!!
Route::get('edit-role-permission/{id}', [AdminController::class, 'editRolePermission'])->name('updateRolePermission');
});
function editRolePermission($id)
{
$row = DB::table('users')
->where('id',$id)
->limit(1)
->update(array('role' => 'fdas'));
return redirect()->back();
}
CodePudding user response:
Change this line:
action="{{ route('updateRolePermission'), ['id' =>$user->id] }}"
to this:
action="{{ route('updateRolePermission', $user->id) }}"
CodePudding user response:
First your route is GET
method while your form is POST
method.
For the $id
, you may get it in your controller by:
$id = \Route::current()->parameter('id');