| @@ 29-38 (lines=10) @@ | ||
| 26 | $this->setTable(config('permission.table_names.permissions')); |
|
| 27 | } |
|
| 28 | ||
| 29 | public static function create(array $attributes = []) |
|
| 30 | { |
|
| 31 | $attributes['guard_name'] = $attributes['guard_name'] ?? config('auth.defaults.guard'); |
|
| 32 | ||
| 33 | if (static::getPermissions()->where('name', $attributes['name'])->where('guard_name', $attributes['guard_name'])->first()) { |
|
| 34 | throw PermissionAlreadyExists::create($attributes['name'], $attributes['guard_name']); |
|
| 35 | } |
|
| 36 | ||
| 37 | return static::query()->create($attributes); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * A permission can be applied to roles. |
|
| @@ 30-39 (lines=10) @@ | ||
| 27 | $this->setTable(config('permission.table_names.roles')); |
|
| 28 | } |
|
| 29 | ||
| 30 | public static function create(array $attributes = []) |
|
| 31 | { |
|
| 32 | $attributes['guard_name'] = $attributes['guard_name'] ?? config('auth.defaults.guard'); |
|
| 33 | ||
| 34 | if (static::where('name', $attributes['name'])->where('guard_name', $attributes['guard_name'])->first()) { |
|
| 35 | throw RoleAlreadyExists::create($attributes['name'], $attributes['guard_name']); |
|
| 36 | } |
|
| 37 | ||
| 38 | return static::query()->create($attributes); |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * A role may be given various permissions. |
|