|
@@ 83-94 (lines=12) @@
|
| 80 |
|
* |
| 81 |
|
* @throws \Spatie\Permission\Exceptions\RoleDoesNotExist |
| 82 |
|
*/ |
| 83 |
|
public static function findByName(string $name, $guardName = null): RoleContract |
| 84 |
|
{ |
| 85 |
|
$guardName = $guardName ?? Guard::getDefaultName(static::class); |
| 86 |
|
|
| 87 |
|
$role = static::where('name', $name)->where('guard_name', $guardName)->first(); |
| 88 |
|
|
| 89 |
|
if (! $role) { |
| 90 |
|
throw RoleDoesNotExist::named($name); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
return $role; |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
public static function findById(int $id, $guardName = null): RoleContract |
| 97 |
|
{ |
|
@@ 96-107 (lines=12) @@
|
| 93 |
|
return $role; |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
public static function findById(int $id, $guardName = null): RoleContract |
| 97 |
|
{ |
| 98 |
|
$guardName = $guardName ?? Guard::getDefaultName(static::class); |
| 99 |
|
|
| 100 |
|
$role = static::where('id', $id)->where('guard_name', $guardName)->first(); |
| 101 |
|
|
| 102 |
|
if (! $role) { |
| 103 |
|
throw RoleDoesNotExist::withId($id); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
return $role; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
/** |
| 110 |
|
* Find or create role by its name (and optionally guardName). |