@@ 51-70 (lines=20) @@ | ||
48 | * @return $this|\Illuminate\Database\Eloquent\Model |
|
49 | * @throws \Maklad\Permission\Exceptions\PermissionAlreadyExists |
|
50 | */ |
|
51 | public static function create(array $attributes = []) |
|
52 | { |
|
53 | $helpers = new Helpers(); |
|
54 | $attributes['guard_name'] = $attributes['guard_name'] ?? \config('auth.defaults.guard'); |
|
55 | ||
56 | if (static::getPermissions()->where('name', $attributes['name'])->where( |
|
57 | 'guard_name', |
|
58 | $attributes['guard_name'] |
|
59 | )->first()) { |
|
60 | $name = (string) $attributes['name']; |
|
61 | $guardName = (string) $attributes['guard_name']; |
|
62 | throw new PermissionAlreadyExists($helpers->getPermissionAlreadyExistsMessage($name, $guardName)); |
|
63 | } |
|
64 | ||
65 | if ($helpers->isNotLumen() && app()::VERSION < '5.4') { |
|
66 | return parent::create($attributes); |
|
67 | } |
|
68 | ||
69 | return static::query()->create($attributes); |
|
70 | } |
|
71 | ||
72 | /** |
|
73 | * Find or create permission by its name (and optionally guardName). |
@@ 53-69 (lines=17) @@ | ||
50 | * @internal param array $attributes§ |
|
51 | * |
|
52 | */ |
|
53 | public static function create(array $attributes = []) |
|
54 | { |
|
55 | $attributes['guard_name'] = $attributes['guard_name'] ?? \config('auth.defaults.guard'); |
|
56 | $helpers = new Helpers(); |
|
57 | ||
58 | if (static::where('name', $attributes['name'])->where('guard_name', $attributes['guard_name'])->first()) { |
|
59 | $name = (string) $attributes['name']; |
|
60 | $guardName = (string) $attributes['guard_name']; |
|
61 | throw new RoleAlreadyExists($helpers->getRoleAlreadyExistsMessage($name, $guardName)); |
|
62 | } |
|
63 | ||
64 | if ($helpers->isNotLumen() && app()::VERSION < '5.4') { |
|
65 | return parent::create($attributes); |
|
66 | } |
|
67 | ||
68 | return static::query()->create($attributes); |
|
69 | } |
|
70 | ||
71 | /** |
|
72 | * Find or create role by its name (and optionally guardName). |