1

I installed the spatie to Laravel permission:

but when I tried to check if the user has rule , this problem appears:

      Call to a member function contains() on null?

my code is:

@role('Admin')
      <p>This message appears if the user is an admin </p>
@endrole

note: if I check using permission like this:

@can('show-post')
<p>This message appears if the user is an admin </p>
@endcan
 

it work, why using role doesn't work?

apokryfos
  • 38,771
  • 9
  • 70
  • 114
Jad es
  • 79
  • 1
  • 12
  • 3
    https://github.com/spatie/laravel-permission/issues/133 Ensure you haven't put stuff in your user model that conflicts with the tool's `permissions` property. – ceejayoz Apr 12 '21 at 13:36
  • Nothing in conflict, is there another solution? – Jad es Apr 12 '21 at 13:43
  • 1
    How about a `roles` column in the database, or any function or property in the User model titled `$roles`, `roles` - `scopeRoles`, `getRolesAttribute`, etc.? – ceejayoz Apr 12 '21 at 13:47
  • 2
    oh , thank you, you are amazing ,it was in user models : protected $casts = [ 'email_verified_at' => 'datetime', 'roles' => 'array' ]; – Jad es Apr 12 '21 at 13:52

0 Answers0