When I click on the Role detail lists all the permissions .
My Controller :
public function permissions($id)
{
$all_permissions = Permission::all(); // All permissions
$role = Role::with('permissions')->where('id', '=', $id)->get(); // Role and role permissions
return view('auth.permissions',compact('role','all_permission'));
}
All permissions in the role of pivot tables list the permissions I want you to be selected
My View file:
@foreach($role as $rol)
{{ $rol->name }}
<tbody>
@foreach($all_permissions as $permision)
<tr>
<td> {{ $permision->id }} </td>
<td> {{ $permision->name }}</td>
<td> {{ $permision->label }} </td>
<td> {{ $permision->updates_at }} </td>
<td>
<input type="checkbox" class="make-switch" checked data-size="small" data-on-color="success" data-on-text="YES" data-off-color="danger" data-off-text="HAYIR"> </li>
</td>
</tr>
@endforeach
</tbody>
@endforeach
Thanks for your help.
I think "contains" method will do what you have wanted:
This is a sample from one of my live projects:
@foreach ($permissions as $permission)
<tr>
<td><label class="css-input css-checkbox css-checkbox-primary">
{!! Form::checkbox('permissions['.$permission->id.']', $permission->id, $role->permissions->contains($permission->id)) !!}<span></span></label></td>
<td>{{ $permission->title }}</td>
<td>{{ $permission->slug }}</td>
<td>{{ $permission->description }}</td>
</tr>
@endforeach