Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
746
vendor/filament/actions/docs/01-overview.md
vendored
Normal file
746
vendor/filament/actions/docs/01-overview.md
vendored
Normal file
|
|
@ -0,0 +1,746 @@
|
|||
---
|
||||
title: Overview
|
||||
---
|
||||
import Aside from "@components/Aside.astro"
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
"Action" is a word that is used quite a bit within the Laravel community. Traditionally, action PHP classes handle "doing" something in your application's business logic. For instance, logging a user in, sending an email, or creating a new user record in the database.
|
||||
|
||||
In Filament, actions also handle "doing" something in your app. However, they are a bit different from traditional actions. They are designed to be used in the context of a user interface. For instance, you might have a button to delete a client record, which opens a modal to confirm your decision. When the user clicks the "Delete" button in the modal, the client is deleted. This whole workflow is an "action".
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->requiresConfirmation()
|
||||
->action(fn () => $this->client->delete())
|
||||
```
|
||||
|
||||
Actions can also collect extra information from the user. For instance, you might have a button to email a client. When the user clicks the button, a modal opens to collect the email subject and body. When the user clicks the "Send" button in the modal, the email is sent:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
Action::make('sendEmail')
|
||||
->schema([
|
||||
TextInput::make('subject')->required(),
|
||||
RichEditor::make('body')->required(),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
Mail::to($this->client)
|
||||
->send(new GenericEmail(
|
||||
subject: $data['subject'],
|
||||
body: $data['body'],
|
||||
));
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$data`, the `action()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
Usually, actions get executed without redirecting the user away from the page. This is because we extensively use Livewire. However, actions can be much simpler, and don't even need a modal. You can pass a URL to an action, and when the user clicks on the button, they are redirected to that page:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `url()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<Aside variant="danger">
|
||||
If you are passing user-controlled data to the `url()` method, you should validate that the URL does not use a dangerous scheme such as `javascript:` or `data:`. Failing to do so could expose your application to XSS attacks. The simplest way to guard against this is to wrap the value in Filament's [`Str::sanitizeUrl()`](../advanced/security#validating-user-input) helper, which returns `null` for any URL that does not use `http`/`https` (or a relative path).
|
||||
</Aside>
|
||||
|
||||
The entire look of the action's trigger button and the modal is customizable using fluent PHP methods. We provide a sensible and consistent styling for the UI, but all of this is customizable with CSS.
|
||||
|
||||
## Available actions
|
||||
|
||||
Filament includes several actions that you can add to your app. Their aim is to simplify the most common Eloquent-related actions:
|
||||
|
||||
- [Create](create)
|
||||
- [Edit](edit)
|
||||
- [View](view)
|
||||
- [Delete](delete)
|
||||
- [Replicate](replicate)
|
||||
- [Force-delete](force-delete)
|
||||
- [Restore](restore)
|
||||
- [Import](import)
|
||||
- [Export](export)
|
||||
|
||||
You can also create your own actions to do anything, these are just common ones that we include out of the box.
|
||||
|
||||
## Choosing a trigger style
|
||||
|
||||
Out of the box, action triggers have 4 styles - "button", "link", "icon button", and "badge".
|
||||
|
||||
"Button" triggers have a background color, label, and optionally an [icon](#setting-an-icon). Usually, this is the default button style, but you can use it manually with the `button()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->button()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/button" alt="Button trigger" version="5.x" />
|
||||
|
||||
"Link" triggers have no background color. They must have a label and optionally an [icon](#setting-an-icon). They look like a link that you might find embedded within text. You can switch to that style with the `link()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->link()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/link" alt="Link trigger" version="5.x" />
|
||||
|
||||
"Icon button" triggers are circular buttons with an [icon](#setting-an-icon) and no label. You can switch to that style with the `iconButton()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->icon('heroicon-m-pencil-square')
|
||||
->iconButton()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/icon-button" alt="Icon button trigger" version="5.x" />
|
||||
|
||||
"Badge" triggers have a background color, label, and optionally an [icon](#setting-an-icon). You can use a badge as trigger using the `badge()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->badge()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/badge" alt="Badge trigger" version="5.x" />
|
||||
|
||||
### Using an icon button on mobile devices only
|
||||
|
||||
You may want to use a button style with a label on desktop, but remove the label on mobile. This will transform it into an icon button. You can do this with the `labeledFrom()` method, passing in the responsive [breakpoint](https://tailwindcss.com/docs/responsive-design#overview) at which you want the label to be added to the button:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->icon('heroicon-m-pencil-square')
|
||||
->button()
|
||||
->labeledFrom('md')
|
||||
```
|
||||
|
||||
## Setting a label
|
||||
|
||||
By default, the label of the trigger button is generated from its name. You may customize this using the `label()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->label('Edit post')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `label()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Setting a color
|
||||
|
||||
Buttons may have a [color](../styling/colors) to indicate their significance:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->color('danger')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `color()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/danger" alt="Red trigger" version="5.x" />
|
||||
|
||||
## Setting a size
|
||||
|
||||
Buttons come in 3 sizes - `Size::Small`, `Size::Medium` or `Size::Large`. You can change the size of the action's trigger using the `size()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Support\Enums\Size;
|
||||
|
||||
Action::make('create')
|
||||
->size(Size::Large)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `size()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/large" alt="Large trigger" version="5.x" />
|
||||
|
||||
## Setting an icon
|
||||
|
||||
Buttons may have an [icon](../styling/icons) to add more detail to the UI. You can set the icon using the `icon()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->icon('heroicon-m-pencil-square')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `icon()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/icon" alt="Trigger with icon" version="5.x" />
|
||||
|
||||
You can also change the icon's position to be after the label instead of before it, using the `iconPosition()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->icon('heroicon-m-pencil-square')
|
||||
->iconPosition(IconPosition::After)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `iconPosition()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/icon-after" alt="Trigger with icon after the label" version="5.x" />
|
||||
|
||||
## Authorization
|
||||
|
||||
You may conditionally show or hide actions for certain users. To do this, you can use either the `visible()` or `hidden()` methods:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->visible(auth()->user()->can('update', $this->post))
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->hidden(! auth()->user()->can('update', $this->post))
|
||||
```
|
||||
|
||||
This is useful for authorization of certain actions to only users who have permission.
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing static values, the `visible()` and `hidden()` methods also accept functions to dynamically calculate them. You can inject various utilities into the functions as parameters.</UtilityInjection>
|
||||
|
||||
### Authorization using a policy
|
||||
|
||||
You can use a policy to authorize an action. To do this, pass the name of the policy method to the `authorize()` method, and Filament will use the current Eloquent model for that action to find the correct policy:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->authorize('update')
|
||||
```
|
||||
|
||||
<Aside variant="info">
|
||||
If you're using an action in a panel resource or relation manager, you don't need to use the `authorize()` method, since Filament will automatically read the policy based on the resource model for the built-in actions like `CreateAction`, `EditAction` and `DeleteAction`. For more information, visit the [resource authorization](../resources/overview#authorization) section.
|
||||
</Aside>
|
||||
|
||||
If your policy method returns a [response message](https://laravel.com/docs/authorization#policy-responses), you can disable the action instead of hiding it, and add a tooltip containing the message, using the `authorizationTooltip()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->authorize('update')
|
||||
->authorizationTooltip()
|
||||
```
|
||||
|
||||
If the denial does not provide a message (for example, your policy returns plain `false`, or a `Gate::before()` hook short-circuits the check), the action is hidden instead. You can supply a fallback message with `authorizationMessage()` to keep the action visible in that case.
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/authorization-tooltip" alt="Disabled action button with an authorization tooltip" version="5.x" />
|
||||
|
||||
You may instead allow the action to still be clickable even if the user is not authorized, but send a notification containing the response message, using the `authorizationNotification()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->authorize('update')
|
||||
->authorizationNotification()
|
||||
```
|
||||
|
||||
As with `authorizationTooltip()`, the action is hidden if the denial does not provide a message, unless you supply a fallback with `authorizationMessage()`.
|
||||
|
||||
### Disabling a button
|
||||
|
||||
If you want to disable a button instead of hiding it, you can use the `disabled()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->disabled()
|
||||
```
|
||||
|
||||
You can conditionally disable a button by passing a boolean to it:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->disabled(! auth()->user()->can('delete', $this->post))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `disabled()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/disabled" alt="Disabled action button" version="5.x" />
|
||||
|
||||
## Registering keybindings
|
||||
|
||||
You can attach keyboard shortcuts to trigger buttons. These use the same key codes as [Mousetrap](https://craig.is/killing/mice):
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('save')
|
||||
->action(fn () => $this->save())
|
||||
->keyBindings(['command+s', 'ctrl+s'])
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `keyBindings()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Adding a badge to the corner of the button
|
||||
|
||||
You can add a badge to the corner of the button, to display whatever you want. It's useful for displaying a count of something, or a status indicator:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('filter')
|
||||
->iconButton()
|
||||
->icon('heroicon-m-funnel')
|
||||
->badge(5)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `badge()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/badged" alt="Trigger with badge" version="5.x" />
|
||||
|
||||
You can also pass a [color](../styling/colors) to be used for the badge:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('filter')
|
||||
->iconButton()
|
||||
->icon('heroicon-m-funnel')
|
||||
->badge(5)
|
||||
->badgeColor('success')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Badge;;?string;;$badge;;The evaluated value of the badge.">As well as allowing a static value, the `badgeColor()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/success-badged" alt="Trigger with green badge" version="5.x" />
|
||||
|
||||
## Outlined button style
|
||||
|
||||
When you're using the "button" trigger style, you might wish to make it less prominent. You could use a different [color](#setting-a-color), but sometimes you might want to make it outlined instead. You can do this with the `outlined()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->button()
|
||||
->outlined()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/trigger-button/outlined" alt="Outlined trigger button" version="5.x" />
|
||||
|
||||
Optionally, you may pass a boolean value to control if the label should be hidden or not:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->button()
|
||||
->outlined(FeatureFlag::active())
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `outlined()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Adding extra HTML attributes to an action
|
||||
|
||||
You can pass extra HTML attributes to the action via the `extraAttributes()` method, which will be merged onto its outer HTML element. The attributes should be represented by an array, where the key is the attribute name and the value is the attribute value:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
->extraAttributes([
|
||||
'title' => 'Edit this post',
|
||||
])
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `extraAttributes()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<Aside variant="tip">
|
||||
By default, calling `extraAttributes()` multiple times will overwrite the previous attributes. If you wish to merge the attributes instead, you can pass `merge: true` to the method.
|
||||
</Aside>
|
||||
|
||||
## Using actions in schemas
|
||||
|
||||
Action objects can be inserted anywhere in a [schema](../schemas/overview), such as in [form field slots](../forms/overview#adding-extra-content-to-a-field), [section headers and footers](../schemas/sections), or alongside [prime components](../schemas/primes). When an action is used in a schema, it has access to the schema's state via [utility injection](#injecting-utilities-from-a-schema) - you can use `$schemaGet` and `$schemaSet` in closures to read and modify form field values.
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
|
||||
TextInput::make('title')
|
||||
->afterContent(
|
||||
Action::make('generateSlug')
|
||||
->action(function (Get $schemaGet, Set $schemaSet) {
|
||||
$schemaSet('slug', str($schemaGet('title'))->slug());
|
||||
})
|
||||
)
|
||||
|
||||
TextInput::make('slug')
|
||||
```
|
||||
|
||||
### Adding a list of actions to a schema
|
||||
|
||||
If you want to render a list of action buttons on their own row in a schema, without attaching them to a specific field, you can wrap them in an `Actions` layout component:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Components\Actions;
|
||||
|
||||
Actions::make([
|
||||
Action::make('star')
|
||||
->icon('heroicon-m-star'),
|
||||
Action::make('resetStars')
|
||||
->icon('heroicon-m-x-mark')
|
||||
->color('danger'),
|
||||
])
|
||||
```
|
||||
|
||||
<AutoScreenshot name="schemas/layout/actions/independent/simple" alt="Independent actions in a schema" version="5.x" />
|
||||
|
||||
You can make the actions span the full width of the schema using the `fullWidth()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Components\Actions;
|
||||
|
||||
Actions::make([
|
||||
Action::make('star')
|
||||
->icon('heroicon-m-star'),
|
||||
Action::make('resetStars')
|
||||
->icon('heroicon-m-x-mark')
|
||||
->color('danger'),
|
||||
])->fullWidth()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="schemas/layout/actions/independent/full-width" alt="Full width independent actions in a schema" version="5.x" />
|
||||
|
||||
You can change the horizontal alignment of the actions using the `alignment()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Components\Actions;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
|
||||
Actions::make([
|
||||
Action::make('star')
|
||||
->icon('heroicon-m-star'),
|
||||
Action::make('resetStars')
|
||||
->icon('heroicon-m-x-mark')
|
||||
->color('danger'),
|
||||
])->alignment(Alignment::Center)
|
||||
```
|
||||
|
||||
<AutoScreenshot name="schemas/layout/actions/independent/horizontally-aligned-center" alt="Center-aligned independent actions in a schema" version="5.x" />
|
||||
|
||||
If the `Actions` component is in a grid alongside other components, you can change its vertical alignment using the `verticalAlignment()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Components\Actions;
|
||||
use Filament\Support\Enums\VerticalAlignment;
|
||||
|
||||
Actions::make([
|
||||
Action::make('star')
|
||||
->icon('heroicon-m-star'),
|
||||
Action::make('resetStars')
|
||||
->icon('heroicon-m-x-mark')
|
||||
->color('danger'),
|
||||
])->verticalAlignment(VerticalAlignment::End)
|
||||
```
|
||||
|
||||
<AutoScreenshot name="schemas/layout/actions/independent/vertically-aligned-end" alt="Independent actions vertically aligned to the end in a schema" version="5.x" />
|
||||
|
||||
### Running JavaScript when an action is clicked
|
||||
|
||||
If you need a simple action that runs JavaScript directly in the browser without making a network request, you can use the `actionJs()` method. This is useful for simple interactions like updating form field values instantly:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
TextInput::make('title')
|
||||
->live(onBlur: true)
|
||||
->afterContent(
|
||||
Action::make('generateSlug')
|
||||
->actionJs(<<<'JS'
|
||||
$set('slug', $get('title').toLowerCase().replaceAll(' ', '-'))
|
||||
JS)
|
||||
)
|
||||
|
||||
TextInput::make('slug')
|
||||
```
|
||||
|
||||
The JavaScript string has access to `$get()` and `$set()` utilities, which allow you to read and modify the state of form fields in the schema.
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `actionJs()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<Aside variant="warning">
|
||||
When using `actionJs()`, the action cannot open a modal or perform any server-side processing. It is intended for simple client-side interactions only. If you need to run PHP code, use the `action()` method instead.
|
||||
</Aside>
|
||||
|
||||
<Aside variant="danger">
|
||||
Any JavaScript string passed to the `actionJs()` method will be executed in the browser, so you should never add user input directly into the string, as it could lead to cross-site scripting (XSS) vulnerabilities. User input from `$get()` should never be evaluated as JavaScript code, but is safe to use as a string value.
|
||||
</Aside>
|
||||
|
||||
## Action utility injection
|
||||
|
||||
The vast majority of methods used to configure actions accept functions as parameters instead of hardcoded values:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
->label('Edit post')
|
||||
->url(fn (): string => route('posts.edit', ['post' => $this->post]))
|
||||
```
|
||||
|
||||
This alone unlocks many customization possibilities.
|
||||
|
||||
The package is also able to inject many utilities to use inside these functions, as parameters. All customization methods that accept functions as arguments can inject utilities.
|
||||
|
||||
These injected utilities require specific parameter names to be used. Otherwise, Filament doesn't know what to inject.
|
||||
|
||||
### Injecting the current modal form data
|
||||
|
||||
If you wish to access the current [modal form data](modals#rendering-a-form-in-a-modal), define a `$data` parameter:
|
||||
|
||||
```php
|
||||
function (array $data) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Be aware that this will be empty if the modal has not been submitted yet.
|
||||
|
||||
### Injecting the Eloquent record
|
||||
|
||||
If your action is associated with an Eloquent record, for example if it is on a table row, you can inject the record using a `$record` parameter:
|
||||
|
||||
```php
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
function (Model $record) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Injecting the current arguments
|
||||
|
||||
If you wish to access the [current arguments](../components/action#passing-action-arguments) that have been passed to the action, define an `$arguments` parameter:
|
||||
|
||||
```php
|
||||
function (array $arguments) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Injecting utilities from a schema
|
||||
|
||||
You can access various additional utilities if your action is defined in a schema:
|
||||
|
||||
- `$schema` - The schema instance that the action belongs to.
|
||||
- `$schemaComponent` - The schema component instance that the action belongs to.
|
||||
- `$schemaComponentState` - The current value of the schema component.
|
||||
- `$schemaState` - The current value of the schema that this action belongs to, like the current repeater item.
|
||||
- `$schemaGet` - A function for retrieving values from the schema data. Validation is not run on form fields.
|
||||
- `$schemaSet` - A function for setting values in the schema data.
|
||||
- `$schemaOperation` - The current operation being performed by the schema. Usually `create`, `edit`, or `view`.
|
||||
|
||||
For more information, please visit the [Schemas section](../schemas/overview#component-utility-injection).
|
||||
|
||||
### Injecting the current Livewire component instance
|
||||
|
||||
If you wish to access the current Livewire component instance that the action belongs to, define a `$livewire` parameter:
|
||||
|
||||
```php
|
||||
use Livewire\Component;
|
||||
|
||||
function (Component $livewire) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Injecting the current action instance
|
||||
|
||||
If you wish to access the current action instance, define a `$action` parameter:
|
||||
|
||||
```php
|
||||
function (Action $action) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Injecting multiple utilities
|
||||
|
||||
The parameters are injected dynamically using reflection, so you are able to combine multiple parameters in any order:
|
||||
|
||||
```php
|
||||
use Livewire\Component;
|
||||
|
||||
function (array $arguments, Component $livewire) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Injecting dependencies from Laravel's container
|
||||
|
||||
You may inject anything from Laravel's container like normal, alongside utilities:
|
||||
|
||||
```php
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
function (Request $request, array $arguments) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
## Rate limiting actions
|
||||
|
||||
You can rate limit actions by using the `rateLimit()` method. This method accepts the number of attempts per minute that a user IP address can make. If the user exceeds this limit, the action will not run and a notification will be shown:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->rateLimit(5)
|
||||
```
|
||||
|
||||
If the action opens a modal, the rate limit will be applied when the modal is submitted.
|
||||
|
||||
If an action is opened with arguments or for a specific Eloquent record, the rate limit will apply to each unique combination of arguments or record for each action. The rate limit is also unique to the current Livewire component / page in a panel.
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `rateLimit()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
### Customizing the rate limited notification
|
||||
|
||||
When an action is rate limited, a notification is dispatched to the user, which indicates the rate limit.
|
||||
|
||||
To customize the title of this notification, use the `rateLimitedNotificationTitle()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteAction;
|
||||
|
||||
DeleteAction::make()
|
||||
->rateLimit(5)
|
||||
->rateLimitedNotificationTitle('Slow down!')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `rateLimitedNotificationTitle()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
You may customize the entire notification using the `rateLimitedNotification()` method:
|
||||
|
||||
```php
|
||||
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
DeleteAction::make()
|
||||
->rateLimit(5)
|
||||
->rateLimitedNotification(
|
||||
fn (TooManyRequestsException $exception): Notification => Notification::make()
|
||||
->warning()
|
||||
->title('Slow down!')
|
||||
->body("You can try deleting again in {$exception->secondsUntilAvailable} seconds."),
|
||||
)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Exception;;DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;;$exception;;The exception encountered when the rate limit was hit.||Minutes until available;;int;;$minutes;;The number of minutes until the rate limit will pass.||Seconds until available;;int;;$seconds;;The number of seconds until the rate limit will pass.||Notification;;Filament\Notifications\Notification;;$notification;;The default notification object for the rate limit, which could be a useful starting point for customization.">As well as allowing a static value, the `rateLimitedNotification()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
### Customizing the rate limit behavior
|
||||
|
||||
If you wish to customize the rate limit behavior, you can use Laravel's [rate limiting](https://laravel.com/docs/rate-limiting#basic-usage) features and Filament's [flash notifications](../notifications/overview) together in the action.
|
||||
|
||||
If you want to rate limit immediately when an action modal is opened, you can do so in the `mountUsing()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
|
||||
Action::make('delete')
|
||||
->mountUsing(function () {
|
||||
if (RateLimiter::tooManyAttempts(
|
||||
$rateLimitKey = 'delete:' . auth()->id(),
|
||||
maxAttempts: 5,
|
||||
)) {
|
||||
Notification::make()
|
||||
->title('Too many attempts')
|
||||
->body('Please try again in ' . RateLimiter::availableIn($rateLimitKey) . ' seconds.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
RateLimiter::hit($rateLimitKey);
|
||||
})
|
||||
```
|
||||
|
||||
If you want to rate limit when an action is run, you can do so in the `action()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
|
||||
Action::make('delete')
|
||||
->action(function () {
|
||||
if (RateLimiter::tooManyAttempts(
|
||||
$rateLimitKey = 'delete:' . auth()->id(),
|
||||
maxAttempts: 5,
|
||||
)) {
|
||||
Notification::make()
|
||||
->title('Too many attempts')
|
||||
->body('Please try again in ' . RateLimiter::availableIn($rateLimitKey) . ' seconds.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
RateLimiter::hit($rateLimitKey);
|
||||
|
||||
// ...
|
||||
})
|
||||
```
|
||||
987
vendor/filament/actions/docs/02-modals.md
vendored
Normal file
987
vendor/filament/actions/docs/02-modals.md
vendored
Normal file
|
|
@ -0,0 +1,987 @@
|
|||
---
|
||||
title: Modals
|
||||
---
|
||||
import Aside from "@components/Aside.astro"
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Actions may require additional confirmation or input from the user before they run. You may open a modal before an action is executed to do this.
|
||||
|
||||
## Confirmation modals
|
||||
|
||||
You may require confirmation before an action is run using the `requiresConfirmation()` method. This is useful for particularly destructive actions, such as those that delete records.
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->action(fn (Post $record) => $record->delete())
|
||||
->requiresConfirmation()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/modal/confirmation" alt="Confirmation modal" version="5.x" />
|
||||
|
||||
<Aside variant="warning">
|
||||
The confirmation modal is not available when a `url()` is set instead of an `action()`. Instead, you should redirect to the URL within the `action()` closure.
|
||||
</Aside>
|
||||
|
||||
<Aside variant="info">
|
||||
Confirmation modals use the `alertdialog` ARIA role instead of `dialog`, so screen readers announce them as alerts and automatically read the modal's description when they open.
|
||||
</Aside>
|
||||
|
||||
## Controlling modal content
|
||||
|
||||
### Customizing the modal's heading, description, and submit action label
|
||||
|
||||
You may customize the heading, description and label of the submit button in the modal:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->action(fn (Post $record) => $record->delete())
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Delete post')
|
||||
->modalDescription('Are you sure you\'d like to delete this post? This cannot be undone.')
|
||||
->modalSubmitActionLabel('Yes, delete it')
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/modal/confirmation-custom-text" alt="Confirmation modal with custom text" version="5.x" />
|
||||
|
||||
### Rendering a schema in a modal
|
||||
|
||||
Filament allows you to render a [schema](../schemas) in a modal, which allows you to render any of the available components to build a UI. Usually, it is useful to build a form in the schema that can collect extra information from the user before the action runs, but any UI can be rendered:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Components\Section;
|
||||
|
||||
Action::make('viewUser')
|
||||
->schema([
|
||||
Grid::make(2)
|
||||
->schema([
|
||||
Section::make('Details')
|
||||
->schema([
|
||||
TextInput::make('name'),
|
||||
Select::make('position')
|
||||
->options([
|
||||
'developer' => 'Developer',
|
||||
'designer' => 'Designer',
|
||||
]),
|
||||
Checkbox::make('is_admin'),
|
||||
]),
|
||||
Section::make('Auditing')
|
||||
->schema([
|
||||
TextEntry::make('created_at')
|
||||
->dateTime(),
|
||||
TextEntry::make('updated_at')
|
||||
->dateTime(),
|
||||
]),
|
||||
]),
|
||||
])
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `schema()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/modal/schema" alt="Modal with schema layout" version="5.x" />
|
||||
|
||||
#### Rendering a form in a modal
|
||||
|
||||
You may use [form field](../forms) to create action modal forms. The data from the form is available in the `$data` array of the `action()` closure:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
Select::make('authorId')
|
||||
->label('Author')
|
||||
->options(User::query()->pluck('name', 'id'))
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data, Post $record): void {
|
||||
$record->author()->associate($data['authorId']);
|
||||
$record->save();
|
||||
})
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/modal/form" alt="Modal with form" version="5.x" />
|
||||
|
||||
##### Filling the form with existing data
|
||||
|
||||
You may fill the form with existing data, using the `fillForm()` method:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->fillForm(fn (Post $record): array => [
|
||||
'authorId' => $record->author->id,
|
||||
])
|
||||
->schema([
|
||||
Select::make('authorId')
|
||||
->label('Author')
|
||||
->options(User::query()->pluck('name', 'id'))
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data, Post $record): void {
|
||||
$record->author()->associate($data['authorId']);
|
||||
$record->save();
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `fillForm()` method also accepts a function to dynamically calculate the data to fill the form with. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
##### Disabling all form fields
|
||||
|
||||
You may wish to disable all form fields in the modal, ensuring the user cannot edit them. You may do so using the `disabledForm()` method:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
Action::make('approvePost')
|
||||
->schema([
|
||||
TextInput::make('title'),
|
||||
Textarea::make('content'),
|
||||
])
|
||||
->disabledForm()
|
||||
->action(function (Post $record): void {
|
||||
$record->approve();
|
||||
})
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/modal/disabled-form" alt="Modal with disabled form fields" version="5.x" />
|
||||
|
||||
#### Rendering a wizard in a modal
|
||||
|
||||
You may create a [multistep form wizard](../schemas/wizards) inside a modal. Instead of using a `schema()`, define a `steps()` array and pass your `Step` objects:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Wizard\Step;
|
||||
|
||||
Action::make('create')
|
||||
->steps([
|
||||
Step::make('Name')
|
||||
->description('Give the category a unique name')
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->live()
|
||||
->afterStateUpdated(fn ($state, callable $set) => $set('slug', Str::slug($state))),
|
||||
TextInput::make('slug')
|
||||
->disabled()
|
||||
->required()
|
||||
->unique(Category::class, 'slug'),
|
||||
])
|
||||
->columns(2),
|
||||
Step::make('Description')
|
||||
->description('Add some extra details')
|
||||
->schema([
|
||||
MarkdownEditor::make('description'),
|
||||
]),
|
||||
Step::make('Visibility')
|
||||
->description('Control who can view it')
|
||||
->schema([
|
||||
Toggle::make('is_visible')
|
||||
->label('Visible to customers.')
|
||||
->default(true),
|
||||
]),
|
||||
])
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/modal/wizard" alt="Modal with wizard" version="5.x" />
|
||||
|
||||
### Adding an icon inside the modal
|
||||
|
||||
You may add an [icon](../styling/icons) inside the modal using the `modalIcon()` method:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->action(fn (Post $record) => $record->delete())
|
||||
->requiresConfirmation()
|
||||
->modalIcon('heroicon-o-trash')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalIcon()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/modal/icon" alt="Confirmation modal with icon" version="5.x" />
|
||||
|
||||
By default, the icon will inherit the color of the action button. You may customize the color of the icon using the `modalIconColor()` method:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->action(fn (Post $record) => $record->delete())
|
||||
->requiresConfirmation()
|
||||
->color('danger')
|
||||
->modalIcon('heroicon-o-trash')
|
||||
->modalIconColor('warning')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalIconColor()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/modal/icon-color" alt="Confirmation modal with custom icon color" version="5.x" />
|
||||
|
||||
### Customizing the alignment of modal content
|
||||
|
||||
By default, modal content will be aligned to the start, or centered if the modal is `xs` or `sm` in [width](#changing-the-modal-width). If you wish to change the alignment of content in a modal, you can use the `modalAlignment()` method and pass it `Alignment::Start` or `Alignment::Center`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->modalAlignment(Alignment::Center)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalAlignment()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/modal/alignment" alt="Modal with centered content alignment" version="5.x" />
|
||||
|
||||
### Making the modal header sticky
|
||||
|
||||
The header of a modal scrolls out of view with the modal content when it overflows the modal size. However, slide-overs have a sticky header that's always visible. You may control this behavior using `stickyModalHeader()`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->stickyModalHeader()
|
||||
```
|
||||
|
||||
### Making the modal footer sticky
|
||||
|
||||
The footer of a modal is rendered inline after the content by default. Slide-overs, however, have a sticky footer that always shows when scrolling the content. You may enable this for a modal too using `stickyModalFooter()`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->stickyModalFooter()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/modal/sticky-header" alt="Modal with sticky header and footer" version="5.x" />
|
||||
|
||||
### Custom modal content
|
||||
|
||||
You may define custom content to be rendered inside your modal, which you can specify by passing a Blade view into the `modalContent()` method:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('advance')
|
||||
->action(fn (Post $record) => $record->advance())
|
||||
->modalContent(view('filament.pages.actions.advance'))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalContent()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
#### Passing data to the custom modal content
|
||||
|
||||
You can pass data to the view by returning it from a function. For example, if the `$record` of an action is set, you can pass that through to the view:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
Action::make('advance')
|
||||
->action(fn (Contract $record) => $record->advance())
|
||||
->modalContent(fn (Contract $record): View => view(
|
||||
'filament.pages.actions.advance',
|
||||
['record' => $record],
|
||||
))
|
||||
```
|
||||
|
||||
#### Adding custom modal content below the form
|
||||
|
||||
By default, the custom content is displayed above the modal form if there is one, but you can add content below using `modalContentFooter()` if you wish:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('advance')
|
||||
->action(fn (Post $record) => $record->advance())
|
||||
->modalContentFooter(view('filament.pages.actions.advance'))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalContentFooter()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
#### Adding an action to custom modal content
|
||||
|
||||
You can add an action button to your custom modal content, which is useful if you want to add a button that performs an action other than the main action. You can do this by registering an action with the `registerModalActions()` method, and then passing it to the view:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
Action::make('advance')
|
||||
->registerModalActions([
|
||||
Action::make('report')
|
||||
->requiresConfirmation()
|
||||
->action(fn (Post $record) => $record->report()),
|
||||
])
|
||||
->action(fn (Post $record) => $record->advance())
|
||||
->modalContent(fn (Action $action): View => view(
|
||||
'filament.pages.actions.advance',
|
||||
['action' => $action],
|
||||
))
|
||||
```
|
||||
|
||||
Now, in the view file, you can render the action button by calling `getModalAction()`:
|
||||
|
||||
```blade
|
||||
<div>
|
||||
{{ $action->getModalAction('report') }}
|
||||
</div>
|
||||
```
|
||||
|
||||
## Using a slide-over instead of a modal
|
||||
|
||||
You can open a "slide-over" dialog instead of a modal by using the `slideOver()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->slideOver()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/modal/slide-over" alt="Slide over with form" version="5.x" />
|
||||
|
||||
Instead of opening in the center of the screen, the modal content will now slide in from the right and consume the entire height of the browser.
|
||||
|
||||
### Changing the slide-over position
|
||||
|
||||
By default, slide-overs enter from the end of the screen (the right side in left-to-right languages, the left side in right-to-left languages). You may change this to the start of the screen by passing `SlideOverPosition::Start` to the `slideOverPosition()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Support\Enums\SlideOverPosition;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->slideOver()
|
||||
->slideOverPosition(SlideOverPosition::Start)
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/modal/slide-over-start" alt="Slide over from the start of the screen" version="5.x" />
|
||||
|
||||
This is useful when the action trigger sits near the start of the viewport — for example, a row action at the beginning of a table row — so the slide-over opens adjacent to its trigger instead of across the screen.
|
||||
|
||||
## Changing the modal width
|
||||
|
||||
You can change the width of the modal by using the `modalWidth()` method. Options correspond to [Tailwind's max-width scale](https://tailwindcss.com/docs/max-width). The options are `ExtraSmall`, `Small`, `Medium`, `Large`, `ExtraLarge`, `TwoExtraLarge`, `ThreeExtraLarge`, `FourExtraLarge`, `FiveExtraLarge`, `SixExtraLarge`, `SevenExtraLarge`, and `Screen`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->modalWidth(Width::FiveExtraLarge)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalWidth()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/modal/wide" alt="Modal with custom width" version="5.x" />
|
||||
|
||||
## Executing code when the modal opens
|
||||
|
||||
You may execute code within a closure when the modal opens, by passing it to the `mountUsing()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
Action::make('create')
|
||||
->mountUsing(function (Schema $form) {
|
||||
$form->fill();
|
||||
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
> The `mountUsing()` method, by default, is used by Filament to initialize the [form](#rendering-a-form-in-a-modal). If you override this method, you will need to call `$form->fill()` to ensure the form is initialized correctly. If you wish to populate the form with data, you can do so by passing an array to the `fill()` method, instead of [using `fillForm()` on the action itself](#filling-the-form-with-existing-data).
|
||||
|
||||
## Customizing the action buttons in the footer of the modal
|
||||
|
||||
By default, there are two actions in the footer of a modal. The first is a button to submit, which executes the `action()`. The second button closes the modal and cancels the action.
|
||||
|
||||
### Modifying the default modal footer action button
|
||||
|
||||
To modify the action instance that is used to render one of the default action buttons, you may pass a closure to the `modalSubmitAction()` and `modalCancelAction()` methods:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('help')
|
||||
->modalContent(view('actions.help'))
|
||||
->modalCancelAction(fn (Action $action) => $action->label('Close'))
|
||||
```
|
||||
|
||||
The [methods available to customize trigger buttons](overview) will work to modify the `$action` instance inside the closure.
|
||||
|
||||
<Aside variant="tip">
|
||||
To customize the button labels in your modal, the `modalSubmitActionLabel()` and `modalCancelActionLabel()` methods can be used instead of passing a function to `modalSubmitAction()` and `modalCancelAction()`, if you don't require any further customizations.
|
||||
</Aside>
|
||||
|
||||
### Removing a default modal footer action button
|
||||
|
||||
To remove a default action, you may pass `false` to either `modalSubmitAction()` or `modalCancelAction()`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('help')
|
||||
->modalContent(view('actions.help'))
|
||||
->modalSubmitAction(false)
|
||||
```
|
||||
|
||||
### Adding an extra modal action button to the footer
|
||||
|
||||
You may pass an array of extra actions to be rendered, between the default actions, in the footer of the modal using the `extraModalFooterActions()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('create')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
// ...
|
||||
->extraModalFooterActions(fn (Action $action): array => [
|
||||
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true]),
|
||||
])
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `extraModalFooterActions()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/modal/extra-footer-actions" alt="Modal with extra footer action buttons" version="5.x" />
|
||||
|
||||
`$action->makeModalSubmitAction()` returns an action instance that can be customized using the [methods available to customize trigger buttons](overview).
|
||||
|
||||
The second parameter of `makeModalSubmitAction()` allows you to pass an array of arguments that will be accessible inside the action's `action()` closure as `$arguments`. These could be useful as flags to indicate that the action should behave differently based on the user's decision:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('create')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
// ...
|
||||
->extraModalFooterActions(fn (Action $action): array => [
|
||||
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true]),
|
||||
])
|
||||
->action(function (array $data, array $arguments): void {
|
||||
// Create
|
||||
|
||||
if ($arguments['another'] ?? false) {
|
||||
// Reset the form and don't close the modal
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
#### Opening another modal from an extra footer action
|
||||
|
||||
You can nest actions within each other, allowing you to open a new modal from an extra footer action:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('edit')
|
||||
// ...
|
||||
->extraModalFooterActions([
|
||||
Action::make('delete')
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
// ...
|
||||
}),
|
||||
])
|
||||
```
|
||||
|
||||
Now, the edit modal will have a "Delete" button in the footer, which will open a confirmation modal when clicked. This action is completely independent of the `edit` action, and will not run the `edit` action when it is clicked.
|
||||
|
||||
In this example though, you probably want to cancel the `edit` action if the `delete` action is run. You can do this using the `cancelParentActions()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('delete')
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
->cancelParentActions()
|
||||
```
|
||||
|
||||
If you have deep nesting with multiple parent actions, but you don't want to cancel all of them, you can pass the name of the parent action you want to cancel, including its children, to `cancelParentActions()`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('first')
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
->extraModalFooterActions([
|
||||
Action::make('second')
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
->extraModalFooterActions([
|
||||
Action::make('third')
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
->extraModalFooterActions([
|
||||
Action::make('fourth')
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
->cancelParentActions('second'),
|
||||
]),
|
||||
]),
|
||||
])
|
||||
```
|
||||
|
||||
In this example, if the `fourth` action is run, the `second` action is canceled, but so is the `third` action since it is a child of `second`. The `first` action is not canceled, however, since it is the parent of `second`. The `first` action's modal will remain open.
|
||||
|
||||
## Accessing information about parent actions from a child
|
||||
|
||||
You can access the instances of parent actions and their raw data and arguments by injecting the `$mountedActions` array in a function used by your nested action. For example, to get the top-most parent action currently active on the page, you can use `$mountedActions[0]`. From there, you can get the raw data for that action by calling `$mountedActions[0]->getRawData()`. Please be aware that raw data is not validated since the action has not been submitted yet:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
Action::make('first')
|
||||
->schema([
|
||||
TextInput::make('foo'),
|
||||
])
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
->extraModalFooterActions([
|
||||
Action::make('second')
|
||||
->requiresConfirmation()
|
||||
->action(function (array $mountedActions) {
|
||||
dd($mountedActions[0]->getRawData());
|
||||
|
||||
// ...
|
||||
}),
|
||||
])
|
||||
```
|
||||
|
||||
You can do similar with the current arguments for a parent action, with the `$mountedActions[0]->getArguments()` method.
|
||||
|
||||
Even if you have multiple layers of nesting, the `$mountedActions` array will contain every action that is currently active, so you can access information about them:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('first')
|
||||
->schema([
|
||||
TextInput::make('foo'),
|
||||
])
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
->extraModalFooterActions([
|
||||
Action::make('second')
|
||||
->schema([
|
||||
TextInput::make('bar'),
|
||||
])
|
||||
->arguments(['number' => 2])
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
->extraModalFooterActions([
|
||||
Action::make('third')
|
||||
->schema([
|
||||
TextInput::make('baz'),
|
||||
])
|
||||
->arguments(['number' => 3])
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
->extraModalFooterActions([
|
||||
Action::make('fourth')
|
||||
->requiresConfirmation()
|
||||
->action(function (array $mountedActions) {
|
||||
dd(
|
||||
$mountedActions[0]->getRawData(),
|
||||
$mountedActions[0]->getArguments(),
|
||||
$mountedActions[1]->getRawData(),
|
||||
$mountedActions[1]->getArguments(),
|
||||
$mountedActions[2]->getRawData(),
|
||||
$mountedActions[2]->getArguments(),
|
||||
);
|
||||
// ...
|
||||
}),
|
||||
]),
|
||||
]),
|
||||
])
|
||||
```
|
||||
|
||||
## Closing the modal
|
||||
|
||||
### Closing the modal by clicking away
|
||||
|
||||
By default, when you click away from a modal, it will close itself. If you wish to disable this behavior for a specific action, you can use the `closeModalByClickingAway(false)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->closeModalByClickingAway(false)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `closeModalByClickingAway()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
If you'd like to change the behavior for all modals in the application, you can do so by calling `ModalComponent::closedByClickingAway()` inside a service provider or middleware:
|
||||
|
||||
```php
|
||||
use Filament\Support\View\Components\ModalComponent;
|
||||
|
||||
ModalComponent::closedByClickingAway(false);
|
||||
```
|
||||
|
||||
### Closing the modal by escaping
|
||||
|
||||
By default, when you press escape on a modal, it will close itself. If you wish to disable this behavior for a specific action, you can use the `closeModalByEscaping(false)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->closeModalByEscaping(false)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `closeModalByEscaping()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
If you'd like to change the behavior for all modals in the application, you can do so by calling `ModalComponent::closedByEscaping()` inside a service provider or middleware:
|
||||
|
||||
```php
|
||||
use Filament\Support\View\Components\ModalComponent;
|
||||
|
||||
ModalComponent::closedByEscaping(false);
|
||||
```
|
||||
|
||||
### Disabling the unsaved changes alert
|
||||
|
||||
When [unsaved changes alerts](../panel-configuration#unsaved-changes-alerts) are enabled for a panel, users are warned before leaving the page while an action modal is open. If a specific action's modal cannot contain unsaved changes, you can disable the warning for it using the `unsavedChangesAlert(false)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
|
||||
Action::make('viewAuthor')
|
||||
->schema([
|
||||
TextEntry::make('name'),
|
||||
TextEntry::make('email'),
|
||||
])
|
||||
->unsavedChangesAlert(false)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `unsavedChangesAlert()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
By default, actions with a [disabled schema](#disabling-all-form-fields), such as `ViewAction`, do not trigger the alert, since their modals do not accept user input.
|
||||
|
||||
### Hiding the modal close button
|
||||
|
||||
By default, modals have a close button in the top right corner. If you wish to hide the close button, you can use the `modalCloseButton(false)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->modalCloseButton(false)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalCloseButton()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
If you'd like to hide the close button for all modals in the application, you can do so by calling `ModalComponent::closeButton(false)` inside a service provider or middleware:
|
||||
|
||||
```php
|
||||
use Filament\Support\View\Components\ModalComponent;
|
||||
|
||||
ModalComponent::closeButton(false);
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/modal/no-close-button" alt="Modal without a close button" version="5.x" />
|
||||
|
||||
## Making the modal click-through
|
||||
|
||||
By default, a modal blocks interaction with the rest of the page while it is open. If you want the user to be able to keep interacting with the page behind the modal, you can make it "click-through" using the `modalClickThrough()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->modalClickThrough()
|
||||
```
|
||||
|
||||
When a modal is click-through, its backdrop is removed, clicks outside the modal window pass through to the page beneath, and the page remains scrollable. The modal can still be closed using its close button or by pressing the escape key.
|
||||
|
||||
<Aside variant="info">
|
||||
A click-through modal cannot be closed by clicking away, as that would be incompatible with interacting with the page behind it. Enabling `modalClickThrough()` therefore disables closing by clicking away automatically.
|
||||
</Aside>
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalClickThrough()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Preventing the modal from autofocusing
|
||||
|
||||
By default, modals will autofocus on the first focusable element when opened. If you wish to disable this behavior, you can use the `modalAutofocus(false)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->modalAutofocus(false)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalAutofocus()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
If you'd like to disable autofocus for all modals in the application, you can do so by calling `ModalComponent::autofocus(false)` inside a service provider or middleware:
|
||||
|
||||
```php
|
||||
use Filament\Support\View\Components\ModalComponent;
|
||||
|
||||
ModalComponent::autofocus(false);
|
||||
```
|
||||
|
||||
## Overlaying child action modals on top of parent action modals
|
||||
|
||||
By default, when a child action opens its modal, the parent action's modal is temporarily closed and then reopened after the child action is dismissed. If you'd like the child action's modal to instead appear on top of the parent action's modal (keeping the parent visible underneath), you can use the `overlayParentActions()` method on the child action:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Components\Repeater;
|
||||
|
||||
Action::make('editItems')
|
||||
->slideOver()
|
||||
->schema([
|
||||
Repeater::make('items')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->deleteAction(
|
||||
fn (Action $action) => $action
|
||||
->requiresConfirmation()
|
||||
->overlayParentActions(),
|
||||
),
|
||||
])
|
||||
->action(function () {
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
In this example, when the user clicks the delete button on a repeater item, the confirmation dialog appears on top of the slide-over instead of the slide-over closing first. This creates a smoother experience, especially for actions inside slide-overs or complex forms where closing and reopening the parent would be disorienting.
|
||||
|
||||
<AutoScreenshot name="actions/modal/overlaying-child" alt="Child confirmation modal overlaying a parent slide-over" version="5.x" />
|
||||
|
||||
## Canceling parent actions when a modal is closed
|
||||
|
||||
The `cancelParentActions()` method above only cancels parent actions when the child action is run. If the user closes the child's modal instead — by pressing Escape, clicking the backdrop, or using the close button — by default only that modal is closed, leaving any parent actions still mounted. To also cancel parent actions when the modal is closed, allowing the user to abandon a multi-step flow entirely rather than closing one modal at a time, use the `cancelParentActionsOnClose()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('createPost')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->extraModalFooterActions([
|
||||
Action::make('saveAsDraft')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->cancelParentActionsOnClose()
|
||||
->action(function (): void {
|
||||
// ...
|
||||
}),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
Now, closing the `saveAsDraft` modal will also cancel the `createPost` action and close its modal.
|
||||
|
||||
Like `cancelParentActions()`, you can pass the name of a parent action to cancel back to a specific parent, including its children, rather than all of them:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('editPostMetadata')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->cancelParentActionsOnClose('createPost')
|
||||
->action(function (): void {
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
## Optimizing modal configuration methods
|
||||
|
||||
When you use database queries or other heavy operations inside modal configuration methods like `modalHeading()`, they can be executed more than once. This is because Filament uses these methods to decide whether to render the modal or not, and also to render the modal's content.
|
||||
|
||||
To skip the check that Filament does to decide whether to render the modal, you can use the `modal()` method, which will inform Filament that the modal exists for this action, and it does not need to check again:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->modal()
|
||||
```
|
||||
|
||||
## Conditionally hiding the modal
|
||||
|
||||
You may have a need to conditionally show a modal for confirmation reasons while falling back to the default action. This can be achieved using `modalHidden()`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('create')
|
||||
->action(function (array $data): void {
|
||||
// ...
|
||||
})
|
||||
->modalHidden($this->role !== 'admin')
|
||||
->modalContent(view('filament.pages.actions.create'))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">The `modalHidden()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Adding extra attributes to the modal window
|
||||
|
||||
You can pass extra HTML attributes to the modal window via the `extraModalWindowAttributes()` method, which will be merged onto its outer HTML element. The attributes should be represented by an array, where the key is the attribute name and the value is the attribute value:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->extraModalWindowAttributes(['class' => 'update-author-modal'])
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `extraModalWindowAttributes()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<Aside variant="tip">
|
||||
By default, calling `extraModalWindowAttributes()` multiple times will overwrite the previous attributes. If you wish to merge the attributes instead, you can pass `merge: true` to the method.
|
||||
</Aside>
|
||||
|
||||
|
||||
## Adding extra attributes to the modal overlay
|
||||
|
||||
You can pass extra HTML attributes to the modal overlay via the `extraModalOverlayAttributes()`. The attributes should be represented by an array, where the key is the attribute name and the value is the attribute value:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
Action::make('updateAuthor')
|
||||
->extraModalOverlayAttributes(['class' => 'update-author-overlay'])
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `extraModalOverlayAttributes()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<Aside variant="tip">
|
||||
By default, calling `extraModalOverlayAttributes()` multiple times will overwrite the previous attributes. If you wish to merge the attributes instead, you can pass <code>merge: true</code> to the method.
|
||||
</Aside>
|
||||
182
vendor/filament/actions/docs/03-grouping-actions.md
vendored
Normal file
182
vendor/filament/actions/docs/03-grouping-actions.md
vendored
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
---
|
||||
title: Grouping actions
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
You may group actions together into a dropdown menu by using an `ActionGroup` object. Groups may contain many actions, or other groups:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
|
||||
ActionGroup::make([
|
||||
Action::make('view'),
|
||||
Action::make('edit'),
|
||||
Action::make('delete'),
|
||||
])
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/group/simple" alt="Action group" version="5.x" />
|
||||
|
||||
This page is about customizing the look of the group's trigger button and dropdown.
|
||||
|
||||
## Customizing the group trigger style
|
||||
|
||||
The button which opens the dropdown may be customized in the same way as a normal action. [All the methods available for trigger buttons](overview) may be used to customize the group trigger button:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Support\Enums\Size;
|
||||
|
||||
ActionGroup::make([
|
||||
// Array of actions
|
||||
])
|
||||
->label('More actions')
|
||||
->icon('heroicon-m-ellipsis-vertical')
|
||||
->size(Size::Small)
|
||||
->color('primary')
|
||||
->button()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/group/customized" alt="Action group with custom trigger style" version="5.x" />
|
||||
|
||||
<AutoScreenshot name="tables/actions/group-button" alt="Table with button action group" version="5.x" />
|
||||
|
||||
### Adding a tooltip to the group trigger button
|
||||
|
||||
You may add a tooltip to the group trigger button using the `tooltip()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ActionGroup;
|
||||
|
||||
ActionGroup::make([
|
||||
// Array of actions
|
||||
])
|
||||
->tooltip('Actions')
|
||||
```
|
||||
|
||||
<AutoScreenshot name="tables/actions/group-tooltip" alt="Table with action group tooltip" version="5.x" />
|
||||
|
||||
### Using a grouped button design
|
||||
|
||||
Instead of a dropdown, an action group can render itself as a group of buttons. This design works with and without button labels. To use this feature, use the `buttonGroup()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
|
||||
ActionGroup::make([
|
||||
Action::make('edit')
|
||||
->color('gray')
|
||||
->icon(Heroicon::PencilSquare)
|
||||
->hiddenLabel(),
|
||||
Action::make('delete')
|
||||
->color('gray')
|
||||
->icon(Heroicon::Trash)
|
||||
->hiddenLabel(),
|
||||
])
|
||||
->buttonGroup()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/group/button-group" alt="Action group using the button group design" version="5.x" />
|
||||
|
||||
## Setting the placement of the dropdown
|
||||
|
||||
The dropdown may be positioned relative to the trigger button by using the `dropdownPlacement()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ActionGroup;
|
||||
|
||||
ActionGroup::make([
|
||||
// Array of actions
|
||||
])
|
||||
->dropdownPlacement('top-start')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actionGroups" version="5.x">The `dropdownPlacement()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/group/placement" alt="Action group with top placement style" version="5.x" />
|
||||
|
||||
Alternatively, you may let the dropdown position be automatically determined based on the available space using the `dropdownAutoPlacement()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ActionGroup;
|
||||
|
||||
ActionGroup::make([
|
||||
// Array of actions
|
||||
])
|
||||
->dropdownAutoPlacement()
|
||||
```
|
||||
|
||||
## Adding dividers between actions
|
||||
|
||||
You may add dividers between groups of actions by using nested `ActionGroup` objects:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ActionGroup;
|
||||
|
||||
ActionGroup::make([
|
||||
ActionGroup::make([
|
||||
// Array of actions
|
||||
])->dropdown(false),
|
||||
// Array of actions
|
||||
])
|
||||
```
|
||||
|
||||
The `dropdown(false)` method puts the actions inside the parent dropdown, instead of a new nested dropdown.
|
||||
|
||||
<UtilityInjection set="actionGroups" version="5.x">The `dropdown()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="actions/group/nested" alt="Action groups nested with dividers" version="5.x" />
|
||||
|
||||
## Setting the width of the dropdown
|
||||
|
||||
The dropdown may be set to a width by using the `dropdownWidth()` method. Options correspond to [Tailwind's max-width scale](https://tailwindcss.com/docs/max-width). The options are `ExtraSmall`, `Small`, `Medium`, `Large`, `ExtraLarge`, `TwoExtraLarge`, `ThreeExtraLarge`, `FourExtraLarge`, `FiveExtraLarge`, `SixExtraLarge` and `SevenExtraLarge`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
ActionGroup::make([
|
||||
// Array of actions
|
||||
])
|
||||
->dropdownWidth(Width::ExtraSmall)
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/group/dropdown-width" alt="Action group with custom dropdown width" version="5.x" />
|
||||
|
||||
<UtilityInjection set="actionGroups" version="5.x">The `dropdownWidth()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Controlling the dropdown offset
|
||||
|
||||
You may control the offset of the dropdown using the `dropdownOffset()` method, by default the offset is set to `8`.
|
||||
|
||||
```php
|
||||
use Filament\Actions\ActionGroup;
|
||||
|
||||
ActionGroup::make([
|
||||
// Array of actions
|
||||
])
|
||||
->dropdownOffset(16)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actionGroups" version="5.x">The `dropdownOffset()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Controlling the maximum height of the dropdown
|
||||
|
||||
The dropdown content can have a maximum height using the `maxHeight()` method, so that it scrolls. You can pass a [CSS length](https://developer.mozilla.org/en-US/docs/Web/CSS/length):
|
||||
|
||||
```php
|
||||
use Filament\Actions\ActionGroup;
|
||||
|
||||
ActionGroup::make([
|
||||
// Array of actions
|
||||
])
|
||||
->maxHeight('400px')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actionGroups" version="5.x">The `maxHeight()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
306
vendor/filament/actions/docs/04-create.md
vendored
Normal file
306
vendor/filament/actions/docs/04-create.md
vendored
Normal file
|
|
@ -0,0 +1,306 @@
|
|||
---
|
||||
title: Create action
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament includes an action that is able to create Eloquent records. When the trigger button is clicked, a modal will open with a form inside. The user fills the form, and that data is validated and saved into the database. You may use it like so:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
CreateAction::make()
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
// ...
|
||||
])
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/create-action/modal" alt="Create action modal" version="5.x" />
|
||||
|
||||
## Customizing data before saving
|
||||
|
||||
Sometimes, you may wish to modify form data before it is finally saved to the database. To do this, you may use the `mutateDataUsing()` method, which has access to the `$data` as an array, and returns the modified version:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->mutateDataUsing(function (array $data): array {
|
||||
$data['user_id'] = auth()->id();
|
||||
|
||||
return $data;
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$data`, the `mutateDataUsing()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Customizing the creation process
|
||||
|
||||
You can tweak how the record is created with the `using()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
CreateAction::make()
|
||||
->using(function (array $data, string $model): Model {
|
||||
return $model::create($data);
|
||||
})
|
||||
```
|
||||
|
||||
`$model` is the class name of the model, but you can replace this with your own hard-coded class if you wish.
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$data` and `$model`, the `using()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Redirecting after creation
|
||||
|
||||
You may set up a custom redirect when the form is submitted using the `successRedirectUrl()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->successRedirectUrl(route('posts.list'))
|
||||
```
|
||||
|
||||
If you want to redirect using the created record, use the `$record` parameter:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
CreateAction::make()
|
||||
->successRedirectUrl(fn (Model $record): string => route('posts.edit', [
|
||||
'post' => $record,
|
||||
]))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Customizing the save notification
|
||||
|
||||
When the record is successfully created, a notification is dispatched to the user, which indicates the success of their action.
|
||||
|
||||
To customize the title of this notification, use the `successNotificationTitle()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->successNotificationTitle('User registered')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `successNotificationTitle()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
You may customize the entire notification using the `successNotification()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
CreateAction::make()
|
||||
->successNotification(
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('User registered')
|
||||
->body('The user has been created successfully.'),
|
||||
)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Notification;;Filament\Notifications\Notification;;$notification;;The default notification object, which could be a useful starting point for customization.">As well as allowing a static value, the `successNotification()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
To disable the notification altogether, use the `successNotification(null)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->successNotification(null)
|
||||
```
|
||||
|
||||
## Lifecycle hooks
|
||||
|
||||
Hooks may be used to execute code at various points within the action's lifecycle, like before a form is saved.
|
||||
|
||||
There are several available hooks:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->beforeFormFilled(function () {
|
||||
// Runs before the form fields are populated with their default values.
|
||||
})
|
||||
->afterFormFilled(function () {
|
||||
// Runs after the form fields are populated with their default values.
|
||||
})
|
||||
->beforeFormValidated(function () {
|
||||
// Runs before the form fields are validated when the form is submitted.
|
||||
})
|
||||
->afterFormValidated(function () {
|
||||
// Runs after the form fields are validated when the form is submitted.
|
||||
})
|
||||
->before(function () {
|
||||
// Runs before the form fields are saved to the database.
|
||||
})
|
||||
->after(function () {
|
||||
// Runs after the form fields are saved to the database.
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">These hook functions can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Halting the creation process
|
||||
|
||||
At any time, you may call `$action->halt()` from inside a lifecycle hook or mutation method, which will halt the entire creation process:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
CreateAction::make()
|
||||
->before(function (CreateAction $action, Post $record) {
|
||||
if (! $record->team->subscribed()) {
|
||||
Notification::make()
|
||||
->warning()
|
||||
->title('You don\'t have an active subscription!')
|
||||
->body('Choose a plan to continue.')
|
||||
->persistent()
|
||||
->actions([
|
||||
Action::make('subscribe')
|
||||
->button()
|
||||
->url(route('subscribe'), shouldOpenInNewTab: true),
|
||||
])
|
||||
->send();
|
||||
|
||||
$action->halt();
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
If you'd like the action modal to close too, you can completely `cancel()` the action instead of halting it:
|
||||
|
||||
```php
|
||||
$action->cancel();
|
||||
```
|
||||
|
||||
## Using a wizard
|
||||
|
||||
You may easily transform the creation process into a multistep wizard. Instead of using a `schema()`, define a `steps()` array and pass your `Step` objects:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Wizard\Step;
|
||||
|
||||
CreateAction::make()
|
||||
->steps([
|
||||
Step::make('Name')
|
||||
->description('Give the category a unique name')
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->live()
|
||||
->afterStateUpdated(fn ($state, callable $set) => $set('slug', Str::slug($state))),
|
||||
TextInput::make('slug')
|
||||
->disabled()
|
||||
->required()
|
||||
->unique(Category::class, 'slug'),
|
||||
])
|
||||
->columns(2),
|
||||
Step::make('Description')
|
||||
->description('Add some extra details')
|
||||
->schema([
|
||||
MarkdownEditor::make('description'),
|
||||
]),
|
||||
Step::make('Visibility')
|
||||
->description('Control who can view it')
|
||||
->schema([
|
||||
Toggle::make('is_visible')
|
||||
->label('Visible to customers.')
|
||||
->default(true),
|
||||
]),
|
||||
])
|
||||
```
|
||||
|
||||
Now, create a new record to see your wizard in action! Edit will still use the form defined within the resource class.
|
||||
|
||||
If you'd like to allow free navigation, so all the steps are skippable, use the `skippableSteps()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->steps([
|
||||
// ...
|
||||
])
|
||||
->skippableSteps()
|
||||
```
|
||||
|
||||
## Creating another record
|
||||
|
||||
### Modifying the create another action
|
||||
|
||||
If you'd like to modify the "create another" action, you may use the `createAnotherAction()` method, passing a function that returns an action. All methods that are available to [customize action trigger buttons](overview) can be used:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->createAnotherAction(fn (Action $action): Action => $action->label('Custom create another label'))
|
||||
```
|
||||
|
||||
### Disabling create another
|
||||
|
||||
If you'd like to remove the "create another" button from the modal, you can use the `createAnother(false)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->createAnother(false)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `createAnother()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
### Preserving data when creating another
|
||||
|
||||
By default, when the user uses the "create and create another" feature, all the form data is cleared so the user can start fresh. If you'd like to preserve some of the data in the form, you may use the `preserveFormDataWhenCreatingAnother()` method, passing an array of fields to preserve:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->preserveFormDataWhenCreatingAnother(['is_admin', 'organization'])
|
||||
```
|
||||
|
||||
Alternatively, you can define a function that returns an array of the `$data` to preserve:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
CreateAction::make()
|
||||
->preserveFormDataWhenCreatingAnother(fn (array $data): array => Arr::only($data, ['is_admin', 'organization']))
|
||||
```
|
||||
|
||||
To preserve all the data, return the entire `$data` array:
|
||||
|
||||
```php
|
||||
use Filament\Actions\CreateAction;
|
||||
|
||||
CreateAction::make()
|
||||
->preserveFormDataWhenCreatingAnother(fn (array $data): array => $data)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `preserveFormDataWhenCreatingAnother()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
223
vendor/filament/actions/docs/05-edit.md
vendored
Normal file
223
vendor/filament/actions/docs/05-edit.md
vendored
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
---
|
||||
title: Edit action
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import Aside from "@components/Aside.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament includes an action that is able to edit Eloquent records. When the trigger button is clicked, a modal will open with a form inside. The user fills the form, and that data is validated and saved into the database. You may use it like so:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
EditAction::make()
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
// ...
|
||||
])
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/edit-action/modal" alt="Edit action modal" version="5.x" />
|
||||
|
||||
## Customizing data before filling the form
|
||||
|
||||
You may wish to modify the data from a record before it is filled into the form. To do this, you may use the `mutateRecordDataUsing()` method to modify the `$data` array, and return the modified version before it is filled into the form:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
EditAction::make()
|
||||
->mutateRecordDataUsing(function (array $data): array {
|
||||
$data['user_id'] = auth()->id();
|
||||
|
||||
return $data;
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$data`, the `mutateRecordDataUsing()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
<Aside variant="warning">
|
||||
Filament fills the form using the record's array representation, which is sent to the browser as part of the Livewire request. If your model has a column containing binary data that is not valid UTF-8, such as a `geometry`, `point`, or `blob` column, it cannot be serialized to JSON and the modal will fail to open, often with no error in the Laravel log.
|
||||
|
||||
To resolve this, add the column to [the `$hidden` array](https://laravel.com/docs/eloquent-serialization#hiding-attributes-from-json) on your model, which excludes it from the model's array and JSON representations:
|
||||
|
||||
```php
|
||||
protected $hidden = ['location'];
|
||||
```
|
||||
|
||||
This applies equally to the [View](view) and [Replicate](replicate) actions.
|
||||
</Aside>
|
||||
|
||||
## Customizing data before saving
|
||||
|
||||
Sometimes, you may wish to modify form data before it is finally saved to the database. To do this, you may use the `mutateDataUsing()` method, which has access to the `$data` as an array, and returns the modified version:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
EditAction::make()
|
||||
->mutateDataUsing(function (array $data): array {
|
||||
$data['last_edited_by_id'] = auth()->id();
|
||||
|
||||
return $data;
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$data`, the `mutateDataUsing()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Customizing the saving process
|
||||
|
||||
You can tweak how the record is updated with the `using()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
EditAction::make()
|
||||
->using(function (Model $record, array $data): Model {
|
||||
$record->update($data);
|
||||
|
||||
return $record;
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$record` and `$data`, the `using()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Redirecting after saving
|
||||
|
||||
You may set up a custom redirect when the form is submitted using the `successRedirectUrl()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
EditAction::make()
|
||||
->successRedirectUrl(route('posts.list'))
|
||||
```
|
||||
|
||||
If you want to redirect using the created record, use the `$record` parameter:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
EditAction::make()
|
||||
->successRedirectUrl(fn (Model $record): string => route('posts.view', [
|
||||
'post' => $record,
|
||||
]))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Customizing the save notification
|
||||
|
||||
When the record is successfully updated, a notification is dispatched to the user, which indicates the success of their action.
|
||||
|
||||
To customize the title of this notification, use the `successNotificationTitle()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
EditAction::make()
|
||||
->successNotificationTitle('User updated')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `successNotificationTitle()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
You may customize the entire notification using the `successNotification()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
EditAction::make()
|
||||
->successNotification(
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('User updated')
|
||||
->body('The user has been saved successfully.'),
|
||||
)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Notification;;Filament\Notifications\Notification;;$notification;;The default notification object, which could be a useful starting point for customization.">As well as allowing a static value, the `successNotification()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
To disable the notification altogether, use the `successNotification(null)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
EditAction::make()
|
||||
->successNotification(null)
|
||||
```
|
||||
|
||||
## Lifecycle hooks
|
||||
|
||||
Hooks may be used to execute code at various points within the action's lifecycle, like before a form is saved.
|
||||
|
||||
There are several available hooks:
|
||||
|
||||
```php
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
EditAction::make()
|
||||
->beforeFormFilled(function () {
|
||||
// Runs before the form fields are populated from the database.
|
||||
})
|
||||
->afterFormFilled(function () {
|
||||
// Runs after the form fields are populated from the database.
|
||||
})
|
||||
->beforeFormValidated(function () {
|
||||
// Runs before the form fields are validated when the form is saved.
|
||||
})
|
||||
->afterFormValidated(function () {
|
||||
// Runs after the form fields are validated when the form is saved.
|
||||
})
|
||||
->before(function () {
|
||||
// Runs before the form fields are saved to the database.
|
||||
})
|
||||
->after(function () {
|
||||
// Runs after the form fields are saved to the database.
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">These hook functions can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Halting the saving process
|
||||
|
||||
At any time, you may call `$action->halt()` from inside a lifecycle hook or mutation method, which will halt the entire saving process:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
EditAction::make()
|
||||
->before(function (EditAction $action, Post $record) {
|
||||
if (! $record->team->subscribed()) {
|
||||
Notification::make()
|
||||
->warning()
|
||||
->title('You don\'t have an active subscription!')
|
||||
->body('Choose a plan to continue.')
|
||||
->persistent()
|
||||
->actions([
|
||||
Action::make('subscribe')
|
||||
->button()
|
||||
->url(route('subscribe'), shouldOpenInNewTab: true),
|
||||
])
|
||||
->send();
|
||||
|
||||
$action->halt();
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
If you'd like the action modal to close too, you can completely `cancel()` the action instead of halting it:
|
||||
|
||||
```php
|
||||
$action->cancel();
|
||||
```
|
||||
41
vendor/filament/actions/docs/06-view.md
vendored
Normal file
41
vendor/filament/actions/docs/06-view.md
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
title: View action
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament includes an action that is able to view Eloquent records. When the trigger button is clicked, a modal will open with information inside. Filament uses form fields to structure this information. All form fields are disabled, so they are not editable by the user. You may use it like so:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
ViewAction::make()
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
// ...
|
||||
])
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/view-action/modal" alt="View action modal" version="5.x" />
|
||||
|
||||
## Customizing data before filling the form
|
||||
|
||||
You may wish to modify the data from a record before it is filled into the form. To do this, you may use the `mutateRecordDataUsing()` method to modify the `$data` array, and return the modified version before it is filled into the form:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ViewAction;
|
||||
|
||||
ViewAction::make()
|
||||
->mutateRecordDataUsing(function (array $data): array {
|
||||
$data['user_id'] = auth()->id();
|
||||
|
||||
return $data;
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$data`, the `mutateRecordDataUsing()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
131
vendor/filament/actions/docs/07-delete.md
vendored
Normal file
131
vendor/filament/actions/docs/07-delete.md
vendored
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
---
|
||||
title: Delete action
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament includes an action that is able to delete Eloquent records. When the trigger button is clicked, a modal asks the user for confirmation. You may use it like so:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteAction;
|
||||
|
||||
DeleteAction::make()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/delete-action/modal" alt="Delete action modal" version="5.x" />
|
||||
|
||||
Or if you want to add it as a table bulk action, so that the user can choose which rows to delete, use `Filament\Actions\DeleteBulkAction`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->toolbarActions([
|
||||
DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
```
|
||||
|
||||
## Redirecting after deleting
|
||||
|
||||
You may set up a custom redirect when the record is deleted using the `successRedirectUrl()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteAction;
|
||||
|
||||
DeleteAction::make()
|
||||
->successRedirectUrl(route('posts.list'))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Customizing the delete notification
|
||||
|
||||
When the record is successfully deleted, a notification is dispatched to the user, which indicates the success of their action.
|
||||
|
||||
To customize the title of this notification, use the `successNotificationTitle()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteAction;
|
||||
|
||||
DeleteAction::make()
|
||||
->successNotificationTitle('User deleted')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `successNotificationTitle()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
You may customize the entire notification using the `successNotification()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
DeleteAction::make()
|
||||
->successNotification(
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('User deleted')
|
||||
->body('The user has been deleted successfully.'),
|
||||
)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Notification;;Filament\Notifications\Notification;;$notification;;The default notification object, which could be a useful starting point for customization.">As well as allowing a static value, the `successNotification()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
To disable the notification altogether, use the `successNotification(null)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteAction;
|
||||
|
||||
DeleteAction::make()
|
||||
->successNotification(null)
|
||||
```
|
||||
|
||||
## Lifecycle hooks
|
||||
|
||||
You can use the `before()` and `after()` methods to execute code before and after a record is deleted:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteAction;
|
||||
|
||||
DeleteAction::make()
|
||||
->before(function () {
|
||||
// ...
|
||||
})
|
||||
->after(function () {
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">These hook functions can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Improving the performance of delete bulk actions
|
||||
|
||||
By default, the `DeleteBulkAction` will load all Eloquent records into memory, before looping over them and deleting them one by one.
|
||||
|
||||
If you are deleting a large number of records, you may want to use the `chunkSelectedRecords()` method to fetch a smaller number of records at a time. This will reduce the memory usage of your application:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
|
||||
DeleteBulkAction::make()
|
||||
->chunkSelectedRecords(250)
|
||||
```
|
||||
|
||||
Filament loads Eloquent records into memory before deleting them for two reasons:
|
||||
|
||||
- To allow individual records in the collection to be authorized with a model policy before deletion (using `authorizeIndividualRecords('delete')`, for example).
|
||||
- To ensure that model events are run when deleting records, such as the `deleting` and `deleted` events in a model observer.
|
||||
|
||||
If you do not require individual record policy authorization and model events, you can use the `fetchSelectedRecords(false)` method, which will not fetch the records into memory before deleting them, and instead will delete them in a single query:
|
||||
|
||||
```php
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
|
||||
DeleteBulkAction::make()
|
||||
->fetchSelectedRecords(false)
|
||||
```
|
||||
155
vendor/filament/actions/docs/08-replicate.md
vendored
Normal file
155
vendor/filament/actions/docs/08-replicate.md
vendored
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
---
|
||||
title: Replicate action
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament includes an action that is able to [replicate](https://laravel.com/docs/eloquent#replicating-models) Eloquent records. You may use it like so:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ReplicateAction;
|
||||
|
||||
ReplicateAction::make()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/replicate-action/modal" alt="Replicate action modal" version="5.x" />
|
||||
|
||||
## Excluding attributes
|
||||
|
||||
The `excludeAttributes()` method is used to instruct the action which columns should be excluded from replication:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ReplicateAction;
|
||||
|
||||
ReplicateAction::make()
|
||||
->excludeAttributes(['slug'])
|
||||
```
|
||||
|
||||
## Customizing data before filling the form
|
||||
|
||||
You may wish to modify the data from a record before it is filled into the form. To do this, you may use the `mutateRecordDataUsing()` method to modify the `$data` array, and return the modified version before it is filled into the form:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ReplicateAction;
|
||||
|
||||
ReplicateAction::make()
|
||||
->mutateRecordDataUsing(function (array $data): array {
|
||||
$data['user_id'] = auth()->id();
|
||||
|
||||
return $data;
|
||||
})
|
||||
```
|
||||
|
||||
## Redirecting after replication
|
||||
|
||||
You may set up a custom redirect when the form is submitted using the `successRedirectUrl()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ReplicateAction;
|
||||
|
||||
ReplicateAction::make()
|
||||
->successRedirectUrl(route('posts.list'))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Replica Eloquent record;;Illuminate\Database\Eloquent\Model;;$replica;;The Eloquent model instance that was just created as a replica of the original record.">As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Customizing the replicate notification
|
||||
|
||||
When the record is successfully replicated, a notification is dispatched to the user, which indicates the success of their action.
|
||||
|
||||
To customize the title of this notification, use the `successNotificationTitle()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ReplicateAction;
|
||||
|
||||
ReplicateAction::make()
|
||||
->successNotificationTitle('Category replicated')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Replica Eloquent record;;Illuminate\Database\Eloquent\Model;;$replica;;The Eloquent model instance that was just created as a replica of the original record.">As well as allowing a static value, the `successNotificationTitle()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
You may customize the entire notification using the `successNotification()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ReplicateAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
ReplicateAction::make()
|
||||
->successNotification(
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Category replicated')
|
||||
->body('The category has been replicated successfully.'),
|
||||
)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Notification;;Filament\Notifications\Notification;;$notification;;The default notification object, which could be a useful starting point for customization.||Replica Eloquent record;;Illuminate\Database\Eloquent\Model;;$replica;;The Eloquent model instance that was just created as a replica of the original record.">As well as allowing a static value, the `successNotification()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
To disable the notification altogether, use the `successNotification(null)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ReplicateAction;
|
||||
|
||||
ReplicateAction::make()
|
||||
->successNotification(null)
|
||||
```
|
||||
|
||||
## Lifecycle hooks
|
||||
|
||||
Hooks may be used to execute code at various points within the action's lifecycle, like before the replica is saved.
|
||||
|
||||
```php
|
||||
use Filament\Actions\ReplicateAction;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
ReplicateAction::make()
|
||||
->before(function () {
|
||||
// Runs before the record has been replicated.
|
||||
})
|
||||
->beforeReplicaSaved(function (Model $replica): void {
|
||||
// Runs after the record has been replicated but before it is saved to the database.
|
||||
})
|
||||
->after(function (Model $replica): void {
|
||||
// Runs after the replica has been saved to the database.
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Replica Eloquent record;;Illuminate\Database\Eloquent\Model;;$replica;;The Eloquent model instance that was just created as a replica of the original record.">These hook functions can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Halting the replication process
|
||||
|
||||
At any time, you may call `$action->halt()` from inside a lifecycle hook, which will halt the entire replication process:
|
||||
|
||||
```php
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ReplicateAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
ReplicateAction::make()
|
||||
->before(function (ReplicateAction $action, Post $record) {
|
||||
if (! $record->team->subscribed()) {
|
||||
Notification::make()
|
||||
->warning()
|
||||
->title('You don\'t have an active subscription!')
|
||||
->body('Choose a plan to continue.')
|
||||
->persistent()
|
||||
->actions([
|
||||
Action::make('subscribe')
|
||||
->button()
|
||||
->url(route('subscribe'), shouldOpenInNewTab: true),
|
||||
])
|
||||
->send();
|
||||
|
||||
$action->halt();
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
If you'd like the action modal to close too, you can completely `cancel()` the action instead of halting it:
|
||||
|
||||
```php
|
||||
$action->cancel();
|
||||
```
|
||||
131
vendor/filament/actions/docs/09-force-delete.md
vendored
Normal file
131
vendor/filament/actions/docs/09-force-delete.md
vendored
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
---
|
||||
title: Force-delete action
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament includes an action that is able to force-delete [soft-deleted](https://laravel.com/docs/eloquent#soft-deleting) Eloquent records. When the trigger button is clicked, a modal asks the user for confirmation. You may use it like so:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
|
||||
ForceDeleteAction::make()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/force-delete-action/modal" alt="Force-delete action modal" version="5.x" />
|
||||
|
||||
Or if you want to add it as a table bulk action, so that the user can choose which rows to force-delete, use `Filament\Actions\ForceDeleteBulkAction`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->toolbarActions([
|
||||
ForceDeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
```
|
||||
|
||||
## Redirecting after force-deleting
|
||||
|
||||
You may set up a custom redirect when the form is submitted using the `successRedirectUrl()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
|
||||
ForceDeleteAction::make()
|
||||
->successRedirectUrl(route('posts.list'))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Customizing the force-delete notification
|
||||
|
||||
When the record is successfully force-deleted, a notification is dispatched to the user, which indicates the success of their action.
|
||||
|
||||
To customize the title of this notification, use the `successNotificationTitle()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
|
||||
ForceDeleteAction::make()
|
||||
->successNotificationTitle('User force-deleted')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `successNotificationTitle()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
You may customize the entire notification using the `successNotification()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
ForceDeleteAction::make()
|
||||
->successNotification(
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('User force-deleted')
|
||||
->body('The user has been force-deleted successfully.'),
|
||||
)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Notification;;Filament\Notifications\Notification;;$notification;;The default notification object, which could be a useful starting point for customization.">As well as allowing a static value, the `successNotification()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
To disable the notification altogether, use the `successNotification(null)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
|
||||
ForceDeleteAction::make()
|
||||
->successNotification(null)
|
||||
```
|
||||
|
||||
## Lifecycle hooks
|
||||
|
||||
You can use the `before()` and `after()` methods to execute code before and after a record is force-deleted:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
|
||||
ForceDeleteAction::make()
|
||||
->before(function () {
|
||||
// ...
|
||||
})
|
||||
->after(function () {
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">These hook functions can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Improving the performance of force-delete bulk actions
|
||||
|
||||
By default, the `ForceDeleteBulkAction` will load all Eloquent records into memory, before looping over them and deleting them one by one.
|
||||
|
||||
If you are deleting a large number of records, you may want to use the `chunkSelectedRecords()` method to fetch a smaller number of records at a time. This will reduce the memory usage of your application:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
|
||||
ForceDeleteBulkAction::make()
|
||||
->chunkSelectedRecords(250)
|
||||
```
|
||||
|
||||
Filament loads Eloquent records into memory before deleting them for two reasons:
|
||||
|
||||
- To allow individual records in the collection to be authorized with a model policy before deletion (using `authorizeIndividualRecords('forceDelete')`, for example).
|
||||
- To ensure that model events are run when deleting records, such as the `forceDeleting` and `forceDeleted` events in a model observer.
|
||||
|
||||
If you do not require individual record policy authorization and model events, you can use the `fetchSelectedRecords(false)` method, which will not fetch the records into memory before deleting them, and instead will delete them in a single query:
|
||||
|
||||
```php
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
|
||||
ForceDeleteBulkAction::make()
|
||||
->fetchSelectedRecords(false)
|
||||
```
|
||||
131
vendor/filament/actions/docs/10-restore.md
vendored
Normal file
131
vendor/filament/actions/docs/10-restore.md
vendored
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
---
|
||||
title: Restore action
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament includes an action that is able to restore [soft-deleted](https://laravel.com/docs/eloquent#soft-deleting) Eloquent records. When the trigger button is clicked, a modal asks the user for confirmation. You may use it like so:
|
||||
|
||||
```php
|
||||
use Filament\Actions\RestoreAction;
|
||||
|
||||
RestoreAction::make()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="actions/restore-action/modal" alt="Restore action modal" version="5.x" />
|
||||
|
||||
Or if you want to add it as a table bulk action, so that the user can choose which rows to restore, use `Filament\Actions\RestoreBulkAction`:
|
||||
|
||||
```php
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->toolbarActions([
|
||||
RestoreBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
```
|
||||
|
||||
## Redirecting after restoring
|
||||
|
||||
You may set up a custom redirect when the form is submitted using the `successRedirectUrl()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\RestoreAction;
|
||||
|
||||
RestoreAction::make()
|
||||
->successRedirectUrl(route('posts.list'))
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Customizing the restore notification
|
||||
|
||||
When the record is successfully restored, a notification is dispatched to the user, which indicates the success of their action.
|
||||
|
||||
To customize the title of this notification, use the `successNotificationTitle()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\RestoreAction;
|
||||
|
||||
RestoreAction::make()
|
||||
->successNotificationTitle('User restored')
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">As well as allowing a static value, the `successNotificationTitle()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
You may customize the entire notification using the `successNotification()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
RestoreAction::make()
|
||||
->successNotification(
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('User restored')
|
||||
->body('The user has been restored successfully.'),
|
||||
)
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x" extras="Notification;;Filament\Notifications\Notification;;$notification;;The default notification object, which could be a useful starting point for customization.">As well as allowing a static value, the `successNotification()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
To disable the notification altogether, use the `successNotification(null)` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\RestoreAction;
|
||||
|
||||
RestoreAction::make()
|
||||
->successNotification(null)
|
||||
```
|
||||
|
||||
## Lifecycle hooks
|
||||
|
||||
You can use the `before()` and `after()` methods to execute code before and after a record is restored:
|
||||
|
||||
```php
|
||||
use Filament\Actions\RestoreAction;
|
||||
|
||||
RestoreAction::make()
|
||||
->before(function () {
|
||||
// ...
|
||||
})
|
||||
->after(function () {
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
<UtilityInjection set="actions" version="5.x">These hook functions can inject various utilities as parameters.</UtilityInjection>
|
||||
|
||||
## Improving the performance of restore bulk actions
|
||||
|
||||
By default, the `RestoreBulkAction` will load all Eloquent records into memory, before looping over them and restoring them one by one.
|
||||
|
||||
If you are restoring a large number of records, you may want to use the `chunkSelectedRecords()` method to fetch a smaller number of records at a time. This will reduce the memory usage of your application:
|
||||
|
||||
```php
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
|
||||
RestoreBulkAction::make()
|
||||
->chunkSelectedRecords(250)
|
||||
```
|
||||
|
||||
Filament loads Eloquent records into memory before restoring them for two reasons:
|
||||
|
||||
- To allow individual records in the collection to be authorized with a model policy before restoration (using `authorizeIndividualRecords('restore')`, for example).
|
||||
- To ensure that model events are run when restoring records, such as the `restoring` and `restored` events in a model observer.
|
||||
|
||||
If you do not require individual record policy authorization and model events, you can use the `fetchSelectedRecords(false)` method, which will not fetch the records into memory before restoring them, and instead will restore them in a single query:
|
||||
|
||||
```php
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
|
||||
RestoreBulkAction::make()
|
||||
->fetchSelectedRecords(false)
|
||||
```
|
||||
1090
vendor/filament/actions/docs/11-import.md
vendored
Normal file
1090
vendor/filament/actions/docs/11-import.md
vendored
Normal file
File diff suppressed because it is too large
Load diff
1071
vendor/filament/actions/docs/12-export.md
vendored
Normal file
1071
vendor/filament/actions/docs/12-export.md
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue