Skip to content

Commit

Permalink
Add the method methodsWithoutModels in AuthorizesRequests Trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieutu committed Apr 24, 2017
1 parent f3a6039 commit cbe1d69
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function authorizeResource($model, $parameter = null, array $options = []
$middleware = [];

foreach ($this->resourceAbilityMap() as $method => $ability) {
$modelName = in_array($method, ['index', 'create', 'store']) ? $model : $parameter;
$modelName = in_array($method, $this->methodsWithoutModels()) ? $model : $parameter;

$middleware["can:{$ability},{$modelName}"][] = $method;
}
Expand All @@ -112,4 +112,14 @@ protected function resourceAbilityMap()
'destroy' => 'delete',
];
}

/**
* Get the list of resource methods which not wait for a parameter.
*
* @return array
*/
protected function methodsWithoutModels()
{
return ['index', 'create', 'store'];
}
}

0 comments on commit cbe1d69

Please sign in to comment.