Action
abstract class Action (View source)
Base class for an Action.
Actions are a mechanism for performing tasks on one or more models – for example, deleting comments, or locking a post. Each item's context menu is made up of a list of Actions.
To define a new action, extend this class, and override and implement methods
as required. Use the Waterhole\Extend\Actions
extender to register an
action class.
Properties
$bulk | Whether the action can be applied to multiple models at once. |
||
$confirm | Whether the action requires confirmation or user input before it is run. |
||
$destructive | Whether the action is destructive, and should have a red appearance. |
Methods
Whether the action should be listed in a menu for the given models.
The label to be displayed in the action button.
The name of an icon to be displayed in the action button.
Any extra attributes for the action button.
Render the action button.
Render the content of the action button.
Confirmation message or view to prompt the user with before the action is run.
Label to be displayed on the confirmation button.
Run the action on the given models.
Details
abstract bool
appliesTo(Model $model)
Whether the action can logically be applied to the given model.
bool
authorize(User|null $user, Model $model)
Whether a user is allowed to apply the action to the given model.
By default, the action can be applied if the user is logged-in.
bool
shouldRender(Collection $models, string $context = null)
Whether the action should be listed in a menu for the given models.
abstract string
label(Collection $models)
The label to be displayed in the action button.
string|null
icon(Collection $models)
The name of an icon to be displayed in the action button.
array
attributes(Collection $models)
Any extra attributes for the action button.
HtmlString
render(Collection $models, array $attributes, bool $tooltip = false)
Render the action button.
protected HtmlString
renderContent(Collection $models, bool $tooltip = false)
Render the content of the action button.
View
confirm(Collection $models)
Confirmation message or view to prompt the user with before the action is run.
string
confirmButton(Collection $models)
Label to be displayed on the confirmation button.
run(Collection $models)
Run the action on the given models.
You can optionally return a response, such as a redirect or a file download. If you don't return anything, Waterhole will keep the user on the current page.
array
stream(Model $model)
Stream partial updates to the page via Turbo Streams.
Return an array of streamRemoved
method if the action is
destructive, and the streamUpdated
method if it isn't.