1

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
7
  • 1
    Your route is GET method while your form is POST method. Commented Nov 27, 2021 at 11:07
  • Route::get(... should be Route::post(... Commented Nov 27, 2021 at 11:09
  • thanks!!, new issues, now, I can send id, but role. Commented Nov 27, 2021 at 11:16
  • There's also a typo: route('updateRolePermission'), ['id' =>$user->id] should be route('updateRolePermission', ['id' =>$user->id]). Voting to close this as a typo (both the GET/POST and the route typo) Commented Nov 27, 2021 at 11:19
  • 1
    Don't change the question after it's solved. If you have other issues, post a new question. I rolled back your updates. If you change it, none of the previous comments/answers will make any sense for future visitors. And if it was a specific answer that helped you solve it, accept that answer Commented Nov 27, 2021 at 11:24

2 Answers 2

1

Change this line:

action="{{ route('updateRolePermission'), ['id' =>$user->id] }}"

to this:

action="{{ route('updateRolePermission', $user->id) }}"
answered Nov 27, 2021 at 11:10
Sign up to request clarification or add additional context in comments.

4 Comments

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.
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 .
I noticed, please read my previous comment.
I posted my comment before reading your comment, that's OK anyway.
0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.