2

In Laravel 8 app using spatie/laravel-permission ^3.18 I defined in bootstrap/app.php

if ( ! defined("PERMISSION_USE_SERVICES")) {
    define("PERMISSION_USE_SERVICES", 'Use services');
}

and in init seeder :

$CustomerRole = Role::create(['name' => ROLE_CUSTOMER, 'guard_name' => 'web']);
$customerUseServicesPermission = Permission::create(['name' => PERMISSION_USE_SERVICES, 'guard_name' => 'web']);
$CustomerRole->givePermissionTo($customerUseServicesPermission); // means : customer use services

and when I register new user in app/Actions/Fortify/CreateNewUser.php I want to give new user customerUseServicesPermission.

In vendor/spatie/laravel-permission/src/Contracts/Permission.php I found method :

interface Permission
{
  public static function findByName(string $name, $guardName): self;

But using it I got error :

Cannot call abstract method Spatie\Permission\Contracts\Permission::findByName()

have I to make wrapper file for Contracts/Permission.php and in which way ?

Thanks!

apokryfos
  • 38,771
  • 9
  • 70
  • 114
mstdmstd
  • 2,195
  • 17
  • 63
  • 140
  • 1
    Accessing laravel-permission model you access it with "use Spatie\Permission\Models\Role;" "use Spatie\Permission\Models\Permission;" instead of "use Spatie\Permission\Contracts\Permission;" for more info https://spatie.be/docs/laravel-permission/v3/advanced-usage/seeding – Doro Jan 14 '21 at 06:53

0 Answers0