# Nova - Actions/Registering-Actions

*Source: https://nova.laravel.com/docs/v5/actions/registering-actions*

---

[Laravel Nova home page](https://nova.laravel.com)
v5
Search...
⌘KAsk AI
- [email protected]
- [Platform Status](https://status.laravel.com/)
- [Dashboard](https://nova.laravel.com)
- [Dashboard](https://nova.laravel.com)
Search...
Navigation
Actions
Registering Actions
[Documentation](/docs/v5/installation)[Knowledge Base](/docs/kb/support)
- [Blog](https://blog.laravel.com)
##### Get Started
- [Installation](/docs/v5/installation)
- [Release Notes](/docs/v5/releases)
- [Upgrade Guide](/docs/v5/upgrade)
##### Resources
- [The Basics](/docs/v5/resources/the-basics)
- [Fields](/docs/v5/resources/fields)
- [Dependent Fields](/docs/v5/resources/dependent-fields)
- [Date Fields](/docs/v5/resources/date-fields)
- [File Fields](/docs/v5/resources/file-fields)
- [Repeater Fields](/docs/v5/resources/repeater-fields)
- [Field Panels](/docs/v5/resources/panels)
- [Relationships](/docs/v5/resources/relationships)
- [Validation](/docs/v5/resources/validation)
- [Authorization](/docs/v5/resources/authorization)
##### Search
- [The Basics](/docs/v5/search/the-basics)
- [Global Search](/docs/v5/search/global-search)
- [Scout Integration](/docs/v5/search/scout-integration)
##### Filters
- [Defining Filters](/docs/v5/filters/defining-filters)
- [Registering Filters](/docs/v5/filters/registering-filters)
##### Lenses
- [Defining Lenses](/docs/v5/lenses/defining-lenses)
- [Registering Lenses](/docs/v5/lenses/registering-lenses)
##### Actions
- [Defining Actions](/docs/v5/actions/defining-actions)
- [Registering Actions](/docs/v5/actions/registering-actions)
##### Metrics
- [Defining Metrics](/docs/v5/metrics/defining-metrics)
- [Registering Metrics](/docs/v5/metrics/registering-metrics)
##### Digging Deeper
- [Dashboards](/docs/v5/customization/dashboards)
- [Menus](/docs/v5/customization/menus)
- [Notifications](/docs/v5/customization/notifications)
- [Authentication](/docs/v5/customization/authentication)
- [Impersonation](/docs/v5/customization/impersonation)
- [Tools](/docs/v5/customization/tools)
- [Resource Tools](/docs/v5/customization/resource-tools)
- [Cards](/docs/v5/customization/cards)
- [Fields](/docs/v5/customization/fields)
- [Filters](/docs/v5/customization/filters)
- [CSS / JavaScript](/docs/v5/customization/frontend)
- [Assets](/docs/v5/customization/assets)
- [Localization](/docs/v5/customization/localization)
- [Stubs](/docs/v5/customization/stubs)
## On this page
- [Authorization](#authorization)
  - [Resource Specific Authorization](#resource-specific-authorization)
  - [Authorization via Resource Policy](#authorization-via-resource-policy)
- [Action Visibility](#action-visibility)
  - [Inline Actions](#inline-actions)
- [Standalone Actions](#standalone-actions)
- [Sole Actions](#sole-actions)
- [Pivot Actions](#pivot-actions)
  - [Custom Pivot Action Name](#custom-pivot-action-name)
- [Closure Actions](#closure-actions)
- [Static Actions](#static-actions)
  - [Redirect Actions](#redirect-actions)
  - [Visit Actions](#visit-actions)
  - [Danger Actions](#danger-actions)
  - [Custom Modal Actions](#custom-modal-actions)
  - [Open URLs in New Tabs](#open-urls-in-new-tabs)
  - [Downloading Files](#downloading-files)
- [Action Confirmation Modal](#action-confirmation-modal)
  - [Fullscreen / Custom Modal Sizes](#fullscreen-%2F-custom-modal-sizes)
  - [Disabling Action Confirmation](#disabling-action-confirmation)
Actions
# Registering Actions
Registering actions in Nova.
> ## Documentation Index
>
> Fetch the complete documentation index at: <https://nova.laravel.com/docs/llms.txt>
>
> Use this file to discover all available pages before exploring further.
Once you have defined an action, you are ready to attach it to a resource. Each resource generated by Nova contains an `actions` method. To attach an action to a resource, you should simply add it to the array of actions returned by this method:
Construct
Make
```
use App\Nova\Actions\EmailAccountProfile;
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array
{
    return [
        new Actions\EmailAccountProfile,
    ];
}
```
## [​](#authorization) Authorization
If you would like to only expose a given action to certain users, you may invoke the `canSee` 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:
app/Nova/~Resource.php
```
use App\Models\User as UserModel;
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array
{
    return [
        Actions\EmailAccountProfile::make()
            ->canSee(function ($request) {
                return $request->user()->can(
                    'emailAnyAccountProfile', UserModel::class
                );
            }),
    ];
}
```
You may also use a variety of request methods to get the currently selected resources:
| 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) 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 the `canRun` 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:
app/Nova/~Resource.php
```
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array
{
    return [
        Actions\EmailAccountProfile::make()
            ->canSee(function ($request) {
                return true;
            })->canRun(function ($request, $user) {
                return $request->user()->can('emailAccountProfile', $user);
            }),
    ];
}
```
### [​](#authorization-via-resource-policy) Authorization via Resource Policy
In addition to the `canSee` 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:
1. Use the return value of the action’s `canRun` method if the method is defined.
2. Use the return value of the underlying model policy’s `runAction` or `runDestructiveAction` methods if those methods have been defined.
3. Use the return value of the underlying model policy’s `update` or `delete` methods if those methods have been defined.
4. Otherwise, return `false`.
## [​](#action-visibility) 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:
- `onlyOnIndex`
- `exceptOnIndex`
- `showOnIndex`
- `onlyOnDetail`
- `exceptOnDetail`
- `showOnDetail`
- `onlyInline`
- `exceptInline`
- `showInline`
### [​](#inline-actions) 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 the `showInline` method when attaching the action to the resource:
app/Nova/~Resource.php
```
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array
{
    return [
        Actions\ConsolidateTransaction::make()
            ->showInline(),
    ];
}
```
## [​](#standalone-actions) 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 the `standalone` method when registering the action. These actions always receives an empty collection of models in their `handle` method:
app/Nova/~Resource.php
```
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array
{
    return [
        Actions\InviteUser::make()
            ->standalone(),
    ];
}
```
## [​](#sole-actions) Sole Actions
Sometimes you may have actions that should only ever be run on a single resource / model. By registering the action as a `sole` 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:
app/Nova/~Resource.php
```
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array
{
    return [
        Actions\BanUser::make()
            ->sole(),
    ];
}
```
## [​](#pivot-actions) Pivot Actions
Typically, actions operate on a resource. However, you may also attach actions to `belongsToMany` 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:
app/Nova/~Resource.php
```
use Laravel\Nova\Fields\BelongsToMany;

// ...

BelongsToMany::make('Roles')
    ->actions(fn () => [new Actions\MarkAsActive]),
```
Once the action has been attached to the field, you will be able to select the action and execute it from the relationship index on the parent resource’s detail page.
#### [​](#custom-pivot-action-name) 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 the `referToPivotAs` method:
app/Nova/~Resource.php
```
use Laravel\Nova\Fields\BelongsToMany;

// ...

BelongsToMany::make('Roles')
    ->actions(fn () => [new Actions\MarkAsActive])
    ->referToPivotAs('Role Assignment'),
```
## [​](#closure-actions) Closure Actions
Closure actions allow you to create actions without defining the action as a separate class. To define a closure action, call the `using` 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:
app/Nova/~Resource.php
```
use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        Action::using('Deactivate User', function (ActionFields $fields, Collection $models) {
            $models->each->update(['active' => false]);
        }),
    ];
}
```
Closure actions are not queueable since they cannot use the `ShouldQueue` trait provided by Laravel.
## [​](#static-actions) 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) Redirect Actions
The `redirect` 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:
app/Nova/~Resource.php
```
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        Action::redirect('Visit Stripe Dashboard', 'https://stripe.com')->standalone(),
    ];
}
```
### [​](#visit-actions) Visit Actions
The `visit` 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:
app/Nova/~Resource.php
```
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Nova;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        Action::visit('View Logs', Nova::url('/logs'))->standalone(),
    ];
}
```
### [​](#danger-actions) Danger Actions
The `danger` 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:
app/Nova/~Resource.php
```
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        Action::danger('Disable User Account', 'This action is no longer available!'),
    ];
}
```
### [​](#custom-modal-actions) Custom Modal Actions
The `modal` 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:
app/Nova/~Resource.php
```
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        Action::modal('Download User Summary', 'UserSummary', function ($user) {
            return [
                'user_id' => $user->getKey(),
            ];
        })->sole(),
    ];
}
```
### [​](#open-urls-in-new-tabs) Open URLs in New Tabs
The `openInNewTab` 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:
app/Nova/~Resource.php
```
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        Action::openInNewTab('Visit Stripe Dashboard', 'https://stripe.com')->standalone(),
    ];
}
```
You may also configure the URL to be unique for a resource by defining a Sole Action:
```
use Laravel\Nova\Actions\Action;

// ...

Action::openInNewTab('Visit User Profile', function ($user) {
    return route('user.profile', $user);
})->sole(),
```
### [​](#downloading-files) Downloading Files
The `downloadUrl` 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:
app/Nova/~Resource.php
```
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        Action::downloadUrl('Download Users Summaries', function () {
            return route('users.summaries');
        })->standalone(),
    ];
}
```
## [​](#action-confirmation-modal) Action Confirmation Modal
### [​](#fullscreen-/-custom-modal-sizes) 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 the `fullscreen` method when registering your action with a given resource:
app/Nova/~Resource.php
```
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        Actions\EmailAccountProfile::make()->fullscreen()
    ];
}
```
Alternatively, you may further customize the maximum width of the customization modal using the `size` method:
app/Nova/~Resource.php
```
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        // "sm", "md", "lg", "xl", "2xl", "3xl", "4xl", "5xl", "6xl", or "7xl"...
        Actions\EmailAccountProfile::make()->size('7xl')
    ];
}
```
### [​](#disabling-action-confirmation) Disabling Action Confirmation
To disable the action confirmation modal and therefore run actions immediately, you can invoke the `withoutConfirmation` method when registering your action with a given resource:
app/Nova/~Resource.php
```
use Laravel\Nova\Http\Requests\NovaRequest;

// ...

/**
 * Get the actions available for the resource.
 *
 * @return array<int, \Laravel\Nova\Actions\Action>
 */
public function actions(NovaRequest $request): array 
{
    return [
        Actions\EmailAccountProfile::make()->withoutConfirmation()
    ];
}
```
Was this page helpful?
YesNo
[Defining Actions](/docs/v5/actions/defining-actions)[Defining Metrics](/docs/v5/metrics/defining-metrics)
⌘I
[Laravel Nova home page](https://nova.laravel.com)
Platform
[Dashboard](https://nova.laravel.com/)[Status](https://status.laravel.com/)
Legal and Compliance
[Term of Service](https://nova.laravel.com/terms)[Privacy Policy](https://nova.laravel.com/privacy)
Assistant
Responses are generated using AI and may contain mistakes.