I am building an app that has users and roles. I want users with the Administrator role to be able to change other user roles. For example add/remove them from other roles.
To do this, I have setup a form with checkboxes, which lists out all of the user roles available:
View
<fieldset>
<legend>Groups</legend>
@foreach($roles as $role)
{!! Form::checkbox($role->field) !!} <span>{{ $role->name }}</span><br>
@endforeach
</fieldset>
This results in the following being produced:
[] Administrator
[] Supervisor
[] Employer
[] Contractor
I have a method which I use to load roles that the user belongs to:
/**
* Get all user roles.
*
* @param $id
* @return Collection
*/
public function getUsersRoles($id)
{
return $this->roleUser->where('user_id', $id)->get();
}
The above method returns an object containing each role.
How can I use this method to pre-select roles which the user belongs to on my view?