actions method. To attach an action to a resource, you should simply add it to the array of actions returned by this method:
make method to instantiate your action. Any arguments passed to the make method will be passed to the constructor of your action:
Authorization
If you would like to only expose a given action to certain users, you may invoke thecanSee method when registering your action. The canSee method accepts a closure which should return true or false. The closure will receive the incoming HTTP request:
| Method | Return Type | Description |
|---|---|---|
allResourcesSelected | bool | Returns true if “Select all” selected. |
selectedResourceIds | \Illuminate\Support\Collection|null | Returns null if “Select all” selected or returns a collection of selected resource IDs. |
selectedResources | \Illuminate\Support\Collection|null | Returns null if “Select all” selected or returns a collection of resource models. |
Resource Specific Authorization
Sometimes a user may be able to “see” that an action exists but only “run” that action against certain resources. You may use thecanRun method in conjunction with the canSee method to have full control over authorization in this scenario. The callback passed to the canRun method receives the incoming HTTP request as well as the model the user would like to run the action against:
Authorization via Resource Policy
In addition to thecanSee and canRun authorization methods, Nova will also determine if the resource’s corresponding model policy has runAction and runDestructiveAction methods. Finally, Nova will determine if the user is authorized to update the model or, in the case of destructive actions, delete the model based on the model’s policy methods.
The priority for authorizing the execution of a Nova action is best explained by the following list of steps:
- Use the return value of the action’s
canRunmethod if the method is defined. - Use the return value of the underlying model policy’s
runActionorrunDestructiveActionmethods if those methods have been defined. - Use the return value of the underlying model policy’s
updateordeletemethods if those methods have been defined. - Otherwise, return
false.
Action Visibility
By default, actions are visible on both the resource index and detail pages. However, you may customize an action’s visibility by invoking one of the following methods on the action when registering your action with a particular resource:onlyOnIndexexceptOnIndexshowOnIndexonlyOnDetailexceptOnDetailshowOnDetailonlyInlineexceptInlineshowInline
Inline Actions
Inline actions are actions that are displayed directly on the index table row of a given resource. You may specify that an action should be available inline by calling theshowInline method when attaching the action to the resource:
Standalone Actions
Typically, actions are executed against resources selected on a resource index or detail page. However, sometimes you may have an action that does not require any resources / models to run. In these situations, you may register the action as a “standalone” action by invoking thestandalone method when registering the action. These actions always receives an empty collection of models in their handle method:
Sole Actions
Sometimes you may have actions that should only ever be run on a single resource / model. By registering the action as asole action, Nova will only display the action when a single resource is selected. Sole actions still receive a collection in their handle method, but the collection will only contain a single model:
Pivot Actions
Typically, actions operate on a resource. However, you may also attach actions tobelongsToMany fields so that they can operate on pivot / intermediate table records. To accomplish this, you may chain the actions method onto your field’s definition:
Custom Pivot Action Name
By default, the pivot actions within the action dropdown menu will be grouped as “Pivot”, but you may customize this name using thereferToPivotAs method:
Closure Actions
Closure actions allow you to create actions without defining the action as a separate class. To define a closure action, call theusing factory method on the Action class, passing the action’s name and a closure. The closure given to the using method receives the same parameters as a dedicated action’s handle method:
Closure actions are not queueable since they cannot use the
ShouldQueue trait provided by Laravel.Static Actions
When using Nova, it’s common to define actions to accomplish simple tasks like downloading files, redirecting users, or opening new windows. Luckily, Nova provides static actions, allowing you to accomplish a variety of common tasks without writing a dedicated action of your own.Redirect Actions
Theredirect action will redirect the user to an external URL. To create a redirect action, pass the action name and the URL you would like to redirect the user to:
Visit Actions
Thevisit action will push the user to an internal page inside Nova. To create a visit action, pass the action’s name and the path you want them to visit:
Danger Actions
Thedanger action displays an error toast notification to the user. For instance, your Nova application may have an action that was previously available but is no longer available, and to avoid confusion you may wish to notify the user of its removal. To accomplish this, pass the action name and the message to display to the user:
Custom Modal Actions
Themodal action allows you to display a custom modal to the user. To create a modal action, pass the action name, your custom Vue component, and any additional data that should be made available to the component:
Open URLs in New Tabs
TheopenInNewTab action opens a URL in a new browser tab. To create an openInNewTab action, pass the action name and the URL that should be opened in the new browser tab:
Downloading Files
ThedownloadUrl action downloads the file at the given URL. To create a downloadUrl action, pass the action name and the URL of the file to be downloaded:
Action Confirmation Modal
Fullscreen / Custom Modal Sizes
When running an action, a confirmation modal is typically displayed to the user, allowing them an opportunity to cancel the pending operation. To indicate that the confirmation modal should display as fullscreen, you may invoke thefullscreen method when registering your action with a given resource:
size method:
Disabling Action Confirmation
To disable the action confirmation modal and therefore run actions immediately, you can invoke thewithoutConfirmation method when registering your action with a given resource: