JosephSilber / bouncer

Laravel Eloquent roles and abilities.
MIT License
3.43k stars 330 forks source link

How can I edit and not remove the role already assigned to a user. #590

Open sebastianBH12 opened 2 years ago

sebastianBH12 commented 2 years ago

I need that when editing the information of a user I can also edit the currently assigned role

JosephSilber commented 2 years ago

Can you provide more information?

  1. What are you trying to do?
  2. How are you currently trying to do it?
  3. What would you expect the outcome to be?
  4. What happens instead?
sebastianBH12 commented 2 years ago
  1. What are you trying to do?

I want to edit an existing user's assigned role

  1. How are you currently trying to do it?

$user->update([ 'name'=>request('name') , 'email'=>request('email') ]); Bouncer::sync($user)->roles([]); $role= $request->input('role'); $user->assign($role);

return redirect()->route('users.show', $user);

I take the role selected in the form, remove the previous one and assign a new one

  1. What would you expect the result to be?

that the record in roles_assigned is edited and does not generate a new one

  1. What happens instead?

instead remove the role and create a new one, the idea is to edit the record in the roles_assigned table

Thank you very much for your attention.

JosephSilber commented 2 years ago

Why would you want the record in roles_assigned to be updated instead of simply being replaced? What difference does it make?