You should post your code here instead of linking it as a screenshot.
User roles and permission issue using spatie permission package
as I am using the laravel spatie package for managing users but is not working as I want which is described as follows:
I want this type of view :
as i have created a seeder file for this as shown below:
$permissions = [
[
'name' => 'role-list|role-create|role-edit|role-delete',
'main_group' => 'Role',
'display_name' => 'All'
],
[
'name' => 'role-list',
'main_group' => 'Role',
'display_name' => 'View'
],
[
'name' => 'role-create|role-edit',
'main_group' => 'Role',
'display_name' => 'Insert|Update'
],
[
'name' => 'role-delete',
'main_group' => 'Role',
'display_name' => 'Delete'
],
];
foreach ($permissions as $permission) {
Permission::create($permission);
}
all permissions have been assigned to admin auto using seeder file successfully but when I click on the particular menu in the sidebar it shows me a page with unauthorized access or you do not have permission.
this is my sidebar.blade.php file :
@canany(['role-list','role-create','role-edit','role-delete'])
@can('role-list')
<li><a class="nav-link" href="{{ route('admin.roles.index') }}">Role</a></li>
@endcan
@endcanany
this is my Role controller file (just trying to do with this file right now)
function __construct()
{
$this->middleware('permission:role-list|role-create|role-edit|role-delete', ['only' => ['index', 'create', 'store', 'edit', 'update', 'destroy']]);
$this->middleware('permission:role-list', ['only' => ['index']]);
$this->middleware('permission:role-create|role-edit', ['only' => ['create', 'store', 'edit', 'update']]);
$this->middleware('permission:role-delete', ['only' => ['destroy']]);
}
this is my main.blade.php file for list view with crud part :
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
<div class="breadcrumb-title pe-3">{{ $title }}</div>
<div class="ms-auto">
@can('role-create')
<div class="btn-group">
<a href="{{ route('admin.roles.create') }}" class="btn btn-primary">Add New</a>
</div>
@endcan
</div>
</div>
@deepakagarwal Well seems like you just need to have a foreach that goes over every role. That will create the white boxes. The inside each box, you have a foreach on every permission that exists (+ all). You render those as checkboxes. If a role has that permission (->hasPermission()), you set it to checked. Then you have an on-click handler (livewire perhaps?) that updates that roles permission on ciick.
Please or to participate in this conversation.
