Property | Type | Description | |
---|---|---|---|
$_authorized | |||
$afterFilters | array | The "after" filters registered on the controller. | |
$beforeFilters | array | The "before" filters registered on the controller. | |
$currentAuthority | Sadly, we can't set an empty array as default value here, maybe a PHP Trait bug ? | ||
$currentUser | |||
$params |
Method | Description | |
---|---|---|
afterFilter ( Closure | string $filter, array $options = [] ) : void | Register an "after" filter on the controller. | |
authorize ( $args = null ) | Throws a Efficiently\AuthorityController\Exceptions\AccessDenied exception if the currentAuthority cannot perform the given action. This is usually called in a controller action or before filter to perform the authorization. | |
authorizeResource ( $args = null ) | Sets up a before filter which authorizes the resource using the instance variable. | |
beforeFilter ( Closure | string $filter, array $options = [] ) : void | Register a "before" filter on the controller. | |
callAction ( string $method, array $parameters ) : |
Execute an action on the controller. | |
can ( $args = null ) | Use in the controller or view to check the user's permission for a given action and object. | |
cannot ( $args = null ) | Convenience method which works the same as "can()" but returns the opposite value. | |
flushAuthorityEvents ( $controllerName = null ) : void | Remove all of the Authority-Controller event listeners of the specified controller. | |
forgetAfterFilter ( string $filter ) : void | Remove the given after filter. | |
forgetBeforeFilter ( string $filter ) : void | Remove the given before filter. | |
getAfterFilters ( ) : array | Get the registered "after" filters. | |
getBeforeFilters ( ) : array | Get the registered "before" filters. | |
getCurrentAbility ( ) | alias of getCurrentAuthority() to match CanCan API | |
getCurrentAuthority ( ) | Creates and returns the current user's authority and caches it. If you want to override how the Authority is defined then this is the place. | |
getCurrentUser ( ) | ||
getParams ( ) | } | |
loadAndAuthorizeResource ( $args = null ) | Sets up a before filter which loads and authorizes the current resource. This performs both loadResource() and authorizeResource() and accepts the same arguments. See those methods for details. | |
loadResource ( $args = null ) | Sets up a before filter which loads the model resource into an instance variable. | |
paramsBeforeFilter ( $filter, array $options = [] ) | ||
prependAfterFilter ( string $filter, array $options = [] ) : void | Register a new "after" filter before any "after" filters on the controller. | |
prependBeforeFilter ( string $filter, array $options = [] ) : void | Register a new "before" filter before any "before" filters on the controller. | |
setCurrentAbility ( $ability ) | alias of setCurrentAuthority() to match CanCan API | |
setCurrentAuthority ( $authority ) |
Method | Description | |
---|---|---|
assignAfter ( Illuminate\Routing\Route $route, Illuminate\Http\Request $request, string $method ) : mixed | Apply the applicable after filters to the route. | |
before ( Illuminate\Routing\Route $route, Illuminate\Http\Request $request, string $method ) : mixed | Call the "before" filters for the controller. | |
callFilter ( array $filter, Illuminate\Routing\Route $route, Illuminate\Http\Request $request ) : mixed | Call the given controller filter method. | |
callRouteFilter ( string $filter, array $parameters, Illuminate\Routing\Route $route, Illuminate\Http\Request $request, Illuminate\Http\Response | null $response = null ) : mixed | Call the given route filter. | |
cleanFilterParameters ( array $parameters ) : array | Clean the parameters being passed to a filter callback. | |
filterApplies ( array $filter, Illuminate\Http\Request $request, string $method ) : boolean | Determine if the given filter applies to the request. | |
filterFailsMethod ( array $filter, Illuminate\Http\Request $request, string $method ) : boolean | Determine if the filter fails the method constraints. | |
getAssignableAfter ( string $filter ) : string | Get the assignable after filter for the route. | |
methodExcludedByOptions ( string $method, array $options ) : boolean | Determine if the given options exclude a particular method. | |
parseFilter ( string $filter, array $options ) : array | Parse the given filter and options. | |
removeFilter ( string $removing, array $current ) : array | Remove the given controller filter from the provided filter array. |
protected assignAfter ( Illuminate\Routing\Route $route, Illuminate\Http\Request $request, string $method ) : mixed | ||
$route | Illuminate\Routing\Route | |
$request | Illuminate\Http\Request | |
$method | string | |
return | mixed |
public authorize ( $args = null ) |
show
', $this->author
on every action before authorizing the book.
That first argument is optional and will default to the singular name of the controller.
A hash of options (see below) can also be passed to this method to further customize it.
See loadAndAuthorizeResource() to automatically load the resource too.
Options:
['only
']
Only applies before filter to given actions.
['except
']
Does not apply before filter to given actions.
['singleton
']
Pass true
if this is a singleton resource through a hasOne
association.
['parent
']
True or false depending on if the resource is considered a parent resource. This defaults to true
if a resource
name is given which does not match the controller.
['class
']
The class to use for the model (string). This passed in when the instance variable is not set.
Pass false
if there is no associated class for this resource and it will use a symbol of the resource name.
['instance_name
']
The name of the instance variable for this resource.
['through
']
Authorize conditions on this parent resource when instance isn't available.
['prepend
']
Passing true
will use prependBeforeFilter() instead of a normal beforeFilter(). public authorizeResource ( $args = null ) |
public callAction ( string $method, array $parameters ) : |
||
$method | string | |
$parameters | array | |
return |
protected callFilter ( array $filter, Illuminate\Routing\Route $route, Illuminate\Http\Request $request ) : mixed | ||
$filter | array | |
$route | Illuminate\Routing\Route | |
$request | Illuminate\Http\Request | |
return | mixed |
protected callRouteFilter ( string $filter, array $parameters, Illuminate\Routing\Route $route, Illuminate\Http\Request $request, Illuminate\Http\Response | null $response = null ) : mixed | ||
$filter | string | |
$parameters | array | |
$route | Illuminate\Routing\Route | |
$request | Illuminate\Http\Request | |
$response | Illuminate\Http\Response | null | |
return | mixed |
public can ( $args = null ) |
protected cleanFilterParameters ( array $parameters ) : array | ||
$parameters | array | |
return | array |
public static flushAuthorityEvents ( $controllerName = null ) : void | ||
return | void |
public forgetAfterFilter ( string $filter ) : void | ||
$filter | string | |
return | void |
public forgetBeforeFilter ( string $filter ) : void | ||
$filter | string | |
return | void |
public getAfterFilters ( ) : array | ||
return | array |
protected getAssignableAfter ( string $filter ) : string | ||
$filter | string | |
return | string |
public getBeforeFilters ( ) : array | ||
return | array |
public getCurrentAbility ( ) |
public getCurrentAuthority ( ) |
public loadAndAuthorizeResource ( $args = null ) |
create
' and 'store
' actions will set
the initial attributes based on these conditions. This way these actions will satisfy
the authority restrictions.
Call this method directly on the controller class.
class BooksController extends Controller
{
public function __construct()
{
$this->loadAndAuthorizeResource();
}
}
A resource is not loaded if the instance variable is already set. This makes it easy to override
the behavior through a beforeFilter() on certain actions.
class BooksController extends Controller
{
public function __construct()
{
$this->beforeFilter('findBookByPermalink', ['only' => 'show']);
$this->loadAndAuthorizeResource();
}
protected function findBookByPermalink()
{
$this->book = Book::where('permalink', $this->params['id'])->firstOrFail();
}
}
If a name is provided which does not match the controller it assumes it is a parent resource. Child
resources can then be loaded through it.
class BooksController extends Controller
{
public function __construct()
{
$this->loadResource('author');
$this->loadResource('book', ['through' => 'author']);
}
}
Here the author resource will be loaded before each action using $this->params['author_id']. The book resource
will then be loaded through the $this->author instance variable.
That first argument is optional and will default to the singular name of the controller.
A hash of options (see below) can also be passed to this method to further customize it.
See loadAndAuthorizeResource() to automatically authorize the resource too.
Options:
['only
']
Only applies before filter to given actions.
['except
']
Does not apply before filter to given actions.
['through
']
Load this resource through another one. This should match the name of the parent instance variable or method.
['throughAssociation
']
The name of the association to fetch the child records through the parent resource.
This is normally not needed because it defaults to the pluralized resource name.
['shallow
']
Pass true
to allow this resource to be loaded directly when parent is null
.
Defaults to false
.
['singleton
']
Pass true
if this is a singleton resource through a hasOne
association.
['parent
']
True or false depending on if the resource is considered a parent resource.
This defaults to true
if a resource
name is given which does not match the controller.
['class
']
The class to use for the model (string).
['instanceName
']
The name of the instance variable to load the resource into.
['findBy
']
Find using a different attribute other than id. For example.
$this->loadResource(['findBy' => 'permalink']);
will use where('permalink', $this->params['id'])->firstOrFail()
['idParam
']
Find using a param key other than 'id'. For example:
$this->loadResource(['idParam' => 'url']); // will use find($this->params['url'])
['collection
']
Specify which actions are resource collection actions in addition to index
. This
is usually not necessary because it will try to guess depending on if the id param is present.
$this->loadResource(['collection' => ['sort', 'list']]);
['create
']
Specify which actions are new resource actions in addition to new
, create
and store
.
Pass an action name into here if you would like to build a new resource instead of
fetch one.
$this->loadResource(['create' => 'build']);
['collectionScope
']
The name of the query scope to fetch the collection records of collection actions (E.g. index
action).
$this->loadResource(['collectionScope' => 'scopePopular']); // will use Article::popular()->get(); to fetch records of collection actions
You can pass parameters with an array. For example:
$this->loadResource(['collectionScope' => ['scopeOfType', 'published']]); // will use Article::ofType('published')->get();
By default, collection actions (index
action) returns all the collection record with:
Article::get(); // which is equivalent to Article::get();
['prepend
']
Passing true
will use prependBeforeFilter() instead of a normal beforeFilter(). public loadResource ( $args = null ) |
public paramsBeforeFilter ( $filter, array $options = [] ) | ||
$options | array |
public setCurrentAbility ( $ability ) |
protected array $afterFilters | ||
return | array |
protected array $beforeFilters | ||
return | array |
protected $currentAuthority |