i want to a role permission list (https://phpout.com/wp-content/uploads/2023/11/z4pne.png) image but i can’t set it i have code my table structure and i actually my code is looking like this (https://phpout.com/wp-content/uploads/2023/11/ADku7.png)
my code look like this
<table class="table">
<thead>
<tr>
<th scope="col">Module</th>
<th scope="col">Show</th>
<th scope="col">Create</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
@foreach ($permissions as $k => $permission)
<tr>
@foreach ($permission->roles as $role)
<td>{{ $role->name }}</td>
@endforeach
<td>
<div class="form-check form-switch">
<input class="form-check-input" name="permission[]" type="checkbox" role="switch" value="{{ $permission->id }}" {{ in_array($permission->id, $rolePermissions) ? 'checked' : '' }}>
</div>
</td>
</tr>
@endforeach
</tbody>
i want code like enter image description here so how can set this
2
Answers
if you are using spatie package for permission then I will provide you the similar structure of mine, difference will of may be styling but the overall idea will be exactly like what I am answering.
You will first input the role name and then permissions for each module which will be in your application, create those in seeders so that evertime you don’t have to create manually.
the blade file should look like this, as I used components if you are not used to that use simple input fields.
and then in you controller save this record like this,
Create a permission servie called permission service in App/Services where you will define a function as i used, this step is not nesseary by the way.
and then you will be checking permission in the basis of roles, for example,
You can first fetch roles with their permissions in your controller like this:
And In your blade: