I have the following code that works with the Form Collective package, however this isn't working right now as the package hasn't been updated for 5.5. I am also using Spatie's Laravel Permission package
The code I have is
@foreach ($permissions as $permission)
{{Form::checkbox('permissions[]', $permission->id, $role->permissions ) }}
{{Form::label($permission->name, ucfirst($permission->name)) }}<br>
@endforeach
Which I believe is just looping through the permissions
and if the permission
belongs to the current role
check the box.
How can I achieve this without using the package?
I have currently tried
@foreach ($permissions as $permission)
<div class="checkbox">
<label>
{{ ucfirst($permission->name) }}
</label>
<input type="checkbox" name="permissions[]" value="{{ $permission->id }}">
<br>
</div>
@endforeach
But I'm not sure how to attach the checked attribute based on whether the role has a permission in the list.
Just add the
checked
attribute to the checkbox HTML:if you need to set it upon a condition use the following code:
EDIT
Since i didn't understand the question before i'll add some details.
Assuming that your
Role
model has a collection of attached permissions and it is stored in the attribute$role->permissions
you could doThat way you can check if your role has the permission with id
$permission->id
.