diff --git a/src/Illuminate/Foundation/Auth/Access/AuthorizesResources.php b/src/Illuminate/Foundation/Auth/Access/AuthorizesResources.php index a129be51f7d9..773b96af0b8a 100644 --- a/src/Illuminate/Foundation/Auth/Access/AuthorizesResources.php +++ b/src/Illuminate/Foundation/Auth/Access/AuthorizesResources.php @@ -6,21 +6,6 @@ trait AuthorizesResources { - /** - * Map of resource methods to ability names. - * - * @var array - */ - protected $resourceAbilityMap = [ - 'index' => 'view', - 'create' => 'create', - 'store' => 'create', - 'show' => 'view', - 'edit' => 'update', - 'update' => 'update', - 'delete' => 'delete', - ]; - /** * Authorize a resource action based on the incoming request. * @@ -34,7 +19,9 @@ public function authorizeResource($model, $name = null, array $options = [], $re { $method = array_last(explode('@', with($request ?: request())->route()->getActionName())); - if (! in_array($method, array_keys($this->resourceAbilityMap))) { + $map = $this->resourceAbilityMap(); + + if (! in_array($method, array_keys($map))) { return new ControllerMiddlewareOptions($options); } @@ -42,6 +29,24 @@ public function authorizeResource($model, $name = null, array $options = [], $re $model = $name ?: strtolower(class_basename($model)); } - return $this->middleware("can:{$this->resourceAbilityMap[$method]},{$model}", $options); + return $this->middleware("can:{$map[$method]},{$model}", $options); + } + + /** + * Get the map of resource methods to ability names. + * + * @return array + */ + protected function resourceAbilityMap() + { + return [ + 'index' => 'view', + 'create' => 'create', + 'store' => 'create', + 'show' => 'view', + 'edit' => 'update', + 'update' => 'update', + 'delete' => 'delete', + ]; } }