# Registering Actions

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:

/**
 * Get the actions available for the resource.
 *
 * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
 * @return array
 */
public function actions(NovaRequest $request)
{
    return [
        new Actions\EmailAccountProfile
    ];
}

Alternatively, you may use the make method to instantiate your action. Any arguments passed to the make method will be passed to the constructor of your action:

/**
 * Get the actions available for the resource.
 *
 * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
 * @return array
 */
public function actions(NovaRequest $request)
{
    return [
        Actions\EmailAccountProfile::make()
    ];
}

# 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:

use App\Models\User;
use Laravel\Nova\Http\Requests\NovaRequest;

/**
 * Get the actions available for the resource.
 *
 * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
 * @return array
 */
public function actions(NovaRequest $request)
{
    return [
        (new Actions\EmailAccountProfile)->canSee(function ($request) {
            return $request->user()->can(
                'emailAnyAccountProfile', User::class
            );
        }),
    ];
}

# 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:

/**
 * Get the actions available for the resource.
 *
 * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
 * @return array
 */
public function actions(NovaRequest $request)
{
    return [
        (new Actions\EmailAccountProfile)->canSee(function ($request) {
            return true;
        })->canRun(function ($request, $user) {
            return $request->user()->can('emailAccountProfile', $user);
        }),
    ];
}

# 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

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 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:

/**
 * Get the actions available for the resource.
 *
 * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
 * @return array
 */
public function actions(NovaRequest $request)
{
    return [
        (new ConsolidateTransaction())->showInline()
    ];
}

# 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:

/**
 * Get the actions available for the resource.
 *
 * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
 * @return array
 */
public function actions(NovaRequest $request)
{
    return [
        Actions\InviteUser::make()->standalone()
    ];
}

# 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:

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.

# Disabling Action Confirmation

When running an action, a confirmation modal is typically displayed to the user, allowing them an opportunity to cancel the pending operation. To disable this (and therefore run the action immediately), you can invoke the withoutConfirmation method when registering your action with a given resource:

/**
 * Get the actions available for the resource.
 *
 * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
 * @return array
 */
public function actions(NovaRequest $request)
{
    return [
        Actions\EmailAccountProfile::make()->withoutConfirmation()
    ];
}