| @@ 40-51 (lines=12) @@ | ||
| 37 | * @param Authorizable|null $user |
|
| 38 | * @return static |
|
| 39 | */ |
|
| 40 | public static function makeIfCan($permission, $options, Authorizable $user = null) |
|
| 41 | { |
|
| 42 | if (is_null($user)) { |
|
| 43 | $user = auth()->user(); |
|
| 44 | } |
|
| 45 | ||
| 46 | if ($user->can($permission)) { |
|
| 47 | return static::make($options); |
|
| 48 | } |
|
| 49 | ||
| 50 | return static::make([])->authorized(false); |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Make a button if the user is not authorized. |
|
| @@ 61-72 (lines=12) @@ | ||
| 58 | * @param Authorizable|null $user |
|
| 59 | * @return static |
|
| 60 | */ |
|
| 61 | public static function makeIfCannot($permission, $options, Authorizable $user = null) |
|
| 62 | { |
|
| 63 | if (is_null($user)) { |
|
| 64 | $user = auth()->user(); |
|
| 65 | } |
|
| 66 | ||
| 67 | if (! $user->can($permission)) { |
|
| 68 | return static::make($options); |
|
| 69 | } |
|
| 70 | ||
| 71 | return static::make([])->authorized(false); |
|
| 72 | } |
|
| 73 | ||
| 74 | /** |
|
| 75 | * Set authorization status of the button. |
|