Why do I have this error Call to a member function contains() on array spatie laravel-permission

712 views Asked by At

In my RoleAndPermission seeder I have

        $admin = Role::create(['name' => 'admin']);
     
        Permission::create(['name' => 'create-attribute']);
        Permission::create(['name' => 'delete-attribute']);
        Permission::create(['name' => 'edit-attribute']);
        Permission::create(['name' => 'update-attribute']);
        Permission::create(['name' => 'view-attribute']);
        Permission::create(['name' => 'store-attribute']);
        $admin->givePermissionTo([
            'create-attribute',
            'view-attribute',
            'delete-attribute',
            'edit-attribute',
            'update-attribute',
            'store-attribute'
        ]);

I have created AttributePolicy

public function viewAny(User $user)
      {
        return $user->hasPermissionTo('view-attribute');    
      }

And in Auth service provider gate

 public function boot()
    {
        $this->registerPolicies();

        Gate::define('view-attribute', [AttributePolicy::class, 'viewAny']);
    }

and in my AttributeController

public function index(Request $request)
    {
        if (Gate::allows('view-attribute')) {
        return Inertia::render('Admin/Attribute/Index', []);
        }
    }

but when i try to access attribute index page as an admin i get error Call to a member function contains() on array. I know it is problem with return $user->hasPermissionTo('view-attribute'); but i don't know why, can somebody help me please?

0

There are 0 answers