Closed realtebo closed 1 year ago
Hi @realtebo ,
It's already documented - you must have not read Step 7 in the installation docs? It's exactly about how to fix the can()
directive:
I've just tried following those docs and setting the guard to null
and it worked like a charm for me:
If you want to test the same thing as above you can use this code for your dashboard or custom page:
@extends(backpack_view('blank'))
@section('content')
<h5>Roles:</h5>
@dump(backpack_user()->roles->pluck('name')->toArray())
<h5>Direct Permissions:</h5>
@dump(backpack_user()->getDirectPermissions()->pluck('name')->toArray())
<h5>Indirect Permissions:</h5>
@dump(backpack_user()->getAllPermissions()->pluck('name')->toArray())
<h5>backpack_user()->role('superadmin')</h5>
@if(backpack_user()->role('superadmin'))
<div class="alert alert-success">
True.
</div>
@else
<div class="alert alert-danger">
False.
</div>
@endif
<h5>backpack_user()->can('manage news')</h5>
@if(backpack_user()->can('manage news'))
<div class="alert alert-success">
True.
</div>
@else
<div class="alert alert-danger">
Not true.
</div>
@endif
<h5>role('superadmin')</h5>
@role('superadmin')
<div class="alert alert-success">
True.
</div>
@else
<div class="alert alert-danger">
Not true.
</div>
@endrole
<h5>hasRole('superadmin')</h5>
@hasrole('superadmin')
<div class="alert alert-success">
True.
</div>
@else
<div class="alert alert-danger">
Not true.
</div>
@endrole
<h5>can('manage news')</h5>
@can('manage news')
<div class="alert alert-success">
True.
</div>
@else
<div class="alert alert-danger">
Not true.
</div>
@endrole
@endsection
Let us know if there's any other problem with using Permission and we can document them. But we don't want to go too deep into explaining how to work with Laravel-Permission. After all... that's its own package, from a different vendor. It's normal to follow their docs, not ours.
Cheers!
Thanks for fast reply, and sorry because my question was posted in the wrong repo.
I think it is perfect, but I think it should be linked as a FAQ in the mai backpack doc because, if you us this package and read this doc, you see how to integrate with backpack.
But if you use laravel-permisision without this addon, you have no clue about what to do to make it works
I think that integration with
laravel-permission
is probably something we (as specific company) do in the 99% of our backpack projects.Every time we have some troubles, due to lack of documentation.
I am just going to open a discussion on main backpack github discussion board because of this.
The @can directive, for example, is not automatically working with laravel-permission and we cannot understand why.