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();
}
M. Eriksson
13.7k4 gold badges31 silver badges42 bronze badges
asked Nov 27, 2021 at 11:02
user16466807
2 Answers 2
Change this line:
action="{{ route('updateRolePermission'), ['id' =>$user->id] }}"
to this:
action="{{ route('updateRolePermission', $user->id) }}"
answered Nov 27, 2021 at 11:10
Rouhollah Mazarei
4,1631 gold badge18 silver badges20 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
M. Eriksson
Ah,... there's a typo. They close the route before the argument. That should be pointed out in a comment and then vote to close as a typo though. So the issue isn't the array but rather that typo. This is why it's important to add an explanation to the answer to point out what the issue was, easy to miss otherwise.
Rouhollah Mazarei
In documentation, the example is
route('profile', ['id' => 1]). you can either use the syntax in my answer, or put the , ['id' =>$user->id] INSIDE the parentheses .M. Eriksson
I noticed, please read my previous comment.
Rouhollah Mazarei
I posted my comment before reading your comment, that's OK anyway.
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');
answered Nov 27, 2021 at 11:10
Phil
1,4642 gold badges11 silver badges21 bronze badges
Comments
lang-php
GETmethod while your form isPOSTmethod.Route::get(...should beRoute::post(...route('updateRolePermission'), ['id' =>$user->id]should beroute('updateRolePermission', ['id' =>$user->id]). Voting to close this as a typo (both the GET/POST and the route typo)