| 1 | <?php |
||
| 11 | trait AuthorizesPermissionResources |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Permission resource ability mapping. |
||
| 15 | * |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | protected $resourcePermissionMap = [ |
||
| 19 | 'index' => 'viewAny', |
||
| 20 | 'create' => 'create', |
||
| 21 | 'store' => 'create', |
||
| 22 | 'show' => 'view', |
||
| 23 | 'edit' => 'update', |
||
| 24 | 'update' => 'update', |
||
| 25 | 'destroy' => 'delete', |
||
| 26 | ]; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Authorize a permission resource action based on the incoming request. |
||
| 30 | * |
||
| 31 | * @param string $resource |
||
| 32 | * @param array $options |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | public function authorizePermissionResource(string $resource, array $options = []) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get the map of permission resource methods to ability names. |
||
| 54 | * |
||
| 55 | * @return array |
||
| 56 | */ |
||
| 57 | protected function resourcePermissionMap(): array |
||
| 65 | } |
||
| 66 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.