diff --git a/docs/03-resources/03-creating-records.md b/docs/03-resources/03-creating-records.md
index 759783854c..7b9bbfed56 100644
--- a/docs/03-resources/03-creating-records.md
+++ b/docs/03-resources/03-creating-records.md
@@ -254,7 +254,7 @@ class CreateCategory extends CreateRecord
}
```
-Inside the `getSteps()` array, return your [wizard steps](../../schemas/layouts/wizard):
+Inside the `getSteps()` array, return your [wizard steps](../../schemas/wizards):
```php
use Filament\Forms\Components\MarkdownEditor;
diff --git a/docs/03-resources/04-editing-records.md b/docs/03-resources/04-editing-records.md
index 0724cd2c2b..d851c3a6b8 100644
--- a/docs/03-resources/04-editing-records.md
+++ b/docs/03-resources/04-editing-records.md
@@ -180,7 +180,7 @@ Alternatively, if you're editing records in a modal action, check out the [Actio
## Saving a part of the form independently
-You may want to allow the user to save a part of the form independently of the rest of the form. One way to do this is with a [section action in the header or footer](../../schemas/layouts/section#adding-actions-to-the-sections-header-or-footer). From the `action()` method, you can call `saveFormComponentOnly()`, passing in the `Section` component that you want to save:
+You may want to allow the user to save a part of the form independently of the rest of the form. One way to do this is with a [section action in the header or footer](../../schemas/sections#adding-actions-to-the-sections-header-or-footer). From the `action()` method, you can call `saveFormComponentOnly()`, passing in the `Section` component that you want to save:
```php
use Filament\Actions\Action;
diff --git a/docs/03-resources/07-relation-managers.md b/docs/03-resources/07-relation-managers.md
index 8d49c5ba99..52c46036b4 100644
--- a/docs/03-resources/07-relation-managers.md
+++ b/docs/03-resources/07-relation-managers.md
@@ -32,7 +32,7 @@ From a UX perspective, this solution is only suitable if your related model only
> These are compatible with `BelongsTo`, `HasOne` and `MorphOne` relationships.
-All layout form components ([Grid](../../schemas/layouts/grid#grid-component), [Section](../../schemas/layouts/section), [Fieldset](../../schemas/layouts/fieldset), etc.) have a [`relationship()` method](../../forms/advanced#saving-data-to-relationships). When you use this, all fields within that layout are saved to the related model instead of the owner's model:
+All layout form components ([Grid](../../schemas/layouts#grid-component), [Section](../../schemas/sections), [Fieldset](../../schemas/layouts#fieldset-component), etc.) have a [`relationship()` method](../../forms/advanced#saving-data-to-relationships). When you use this, all fields within that layout are saved to the related model instead of the owner's model:
```php
use Filament\Forms\Components\FileUpload;
@@ -656,7 +656,7 @@ public function hasCombinedRelationManagerTabsWithContent(): bool
### Customizing the content tab
-On the Edit or View page class, override the `getContentTabComponent()` method, and use any [Tab](../../schemas/layouts/tabs) customization methods:
+On the Edit or View page class, override the `getContentTabComponent()` method, and use any [Tab](../../schemas/tabs) customization methods:
```php
use Filament\Schemas\Components\Tabs\Tab;
@@ -683,7 +683,7 @@ public function getContentTabPosition(): ?ContentTabPosition
## Customizing relation manager tabs
-To customize the tab for a relation manager, override the `getTabComponent()` method, and use any [Tab](../../schemas/layouts/tabs) customization methods:
+To customize the tab for a relation manager, override the `getTabComponent()` method, and use any [Tab](../../schemas/tabs) customization methods:
```php
use Filament\Schemas\Components\Tabs\Tab;
diff --git a/packages/actions/docs/01-overview.md b/packages/actions/docs/01-overview.md
index 1a7ba83422..750c56a268 100644
--- a/packages/actions/docs/01-overview.md
+++ b/packages/actions/docs/01-overview.md
@@ -478,7 +478,7 @@ These injected utilities require specific parameter names to be used. Otherwise,
### Injecting the current modal form data
-If you wish to access the current [modal form data](modals#modal-forms), define a `$data` parameter:
+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) {
diff --git a/packages/actions/docs/02-modals.md b/packages/actions/docs/02-modals.md
index dbbc6778d9..9fa9d29099 100644
--- a/packages/actions/docs/02-modals.md
+++ b/packages/actions/docs/02-modals.md
@@ -1,7 +1,9 @@
---
title: Modals
---
+import Aside from "@components/Aside.astro"
import AutoScreenshot from "@components/AutoScreenshot.astro"
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -22,13 +24,72 @@ Action::make('delete')
-> 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.
+
-## Modal forms
+## Controlling modal content
-You may also render a form in the modal to collect extra information from the user before the action runs.
+### Customizing the modal's heading, description, and submit action label
-You may use components from the [Form Builder](../forms) to create custom action modal forms. The data from the form is available in the `$data` array of the `action()` closure:
+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')
+```
+
+
+
+### 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(),
+ ]),
+ ]),
+ ])
+```
+
+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.
+
+#### 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;
@@ -37,7 +98,7 @@ use Filament\Actions\Action;
use Filament\Forms\Components\Select;
Action::make('updateAuthor')
- ->form([
+ ->schema([
Select::make('authorId')
->label('Author')
->options(User::query()->pluck('name', 'id'))
@@ -51,7 +112,7 @@ Action::make('updateAuthor')
-### Filling the form with existing data
+##### Filling the form with existing data
You may fill the form with existing data, using the `fillForm()` method:
@@ -65,7 +126,7 @@ Action::make('updateAuthor')
->fillForm(fn (Post $record): array => [
'authorId' => $record->author->id,
])
- ->form([
+ ->schema([
Select::make('authorId')
->label('Author')
->options(User::query()->pluck('name', 'id'))
@@ -77,9 +138,32 @@ Action::make('updateAuthor')
})
```
-### Using a wizard as a modal form
+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.
-You may create a [multistep form wizard](../schemas/layouts/wizard) inside a modal. Instead of using a `form()`, define a `steps()` array and pass your `Step` objects:
+##### 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();
+ })
+```
+
+#### 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;
@@ -120,51 +204,7 @@ Action::make('create')
-### 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 App\Models\User;
-use Filament\Actions\Action;
-use Filament\Forms\Components\Textarea;
-use Filament\Forms\Components\TextInput;
-
-Action::make('approvePost')
- ->form([
- TextInput::make('title'),
- Textarea::make('content'),
- ])
- ->fillForm(fn (Post $record): array => [
- 'title' => $record->title,
- 'content' => $record->content,
- ])
- ->disabledForm()
- ->action(function (Post $record): void {
- $record->approve();
- })
-```
-
-## 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')
-```
-
-
-
-## Adding an icon inside the modal
+### Adding an icon inside the modal
You may add an [icon](../styling/icons) inside the modal using the `modalIcon()` method:
@@ -178,6 +218,8 @@ Action::make('delete')
->modalIcon('heroicon-o-trash')
```
+The `modalIcon()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
By default, the icon will inherit the color of the action button. You may customize the color of the icon using the `modalIconColor()` method:
@@ -194,7 +236,9 @@ Action::make('delete')
->modalIconColor('warning')
```
-## Customizing the alignment of modal content
+The `modalIconColor()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
+### 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`:
@@ -203,7 +247,7 @@ use Filament\Actions\Action;
use Filament\Support\Enums\Alignment;
Action::make('updateAuthor')
- ->form([
+ ->schema([
// ...
])
->action(function (array $data): void {
@@ -212,7 +256,43 @@ Action::make('updateAuthor')
->modalAlignment(Alignment::Center)
```
-## Custom modal content
+The `modalAlignment()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
+### 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()
+```
+
+### 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:
@@ -225,7 +305,9 @@ Action::make('advance')
->modalContent(view('filament.pages.actions.advance'))
```
-### Passing data to the custom modal content
+The `modalContent()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
+#### 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:
@@ -241,7 +323,7 @@ Action::make('advance')
))
```
-### Adding custom modal content below the form
+#### 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:
@@ -254,7 +336,9 @@ Action::make('advance')
->modalContentFooter(view('filament.pages.actions.advance'))
```
-### Adding an action to custom modal content
+The `modalContentFooter()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
+#### 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:
@@ -292,7 +376,7 @@ You can open a "slide-over" dialog instead of a modal by using the `slideOver()`
use Filament\Actions\Action;
Action::make('updateAuthor')
- ->form([
+ ->schema([
// ...
])
->action(function (array $data): void {
@@ -305,40 +389,6 @@ Action::make('updateAuthor')
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.
-## 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')
- ->form([
- // ...
- ])
- ->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')
- ->form([
- // ...
- ])
- ->action(function (array $data): void {
- // ...
- })
- ->stickyModalFooter()
-```
-
## 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`:
@@ -348,7 +398,7 @@ use Filament\Actions\Action;
use Filament\Support\Enums\Width;
Action::make('updateAuthor')
- ->form([
+ ->schema([
// ...
])
->action(function (array $data): void {
@@ -357,6 +407,8 @@ Action::make('updateAuthor')
->modalWidth(Width::FiveExtraLarge)
```
+The `modalWidth()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
## Executing code when the modal opens
You may execute code within a closure when the modal opens, by passing it to the `mountUsing()` method:
@@ -373,13 +425,13 @@ Action::make('create')
})
```
-> The `mountUsing()` method, by default, is used by Filament to initialize the [form](#modal-forms). 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).
+> 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 a default modal footer action button
+### 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:
@@ -413,7 +465,7 @@ You may pass an array of extra actions to be rendered, between the default actio
use Filament\Actions\Action;
Action::make('create')
- ->form([
+ ->schema([
// ...
])
// ...
@@ -422,6 +474,8 @@ Action::make('create')
])
```
+The `extraModalFooterActions()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
`$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:
@@ -430,7 +484,7 @@ The second parameter of `makeModalSubmitAction()` allows you to pass an array of
use Filament\Actions\Action;
Action::make('create')
- ->form([
+ ->schema([
// ...
])
// ...
@@ -524,7 +578,7 @@ use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
Action::make('first')
- ->form([
+ ->schema([
TextInput::make('foo'),
])
->action(function () {
@@ -549,7 +603,7 @@ Even if you have multiple layers of nesting, the `$mountedActions` array will co
use Filament\Actions\Action;
Action::make('first')
- ->form([
+ ->schema([
TextInput::make('foo'),
])
->action(function () {
@@ -557,7 +611,7 @@ Action::make('first')
})
->extraModalFooterActions([
Action::make('second')
- ->form([
+ ->schema([
TextInput::make('bar'),
])
->arguments(['number' => 2])
@@ -566,7 +620,7 @@ Action::make('first')
})
->extraModalFooterActions([
Action::make('third')
- ->form([
+ ->schema([
TextInput::make('baz'),
])
->arguments(['number' => 3])
@@ -592,7 +646,9 @@ Action::make('first')
])
```
-## Closing the modal by clicking away
+## 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:
@@ -600,7 +656,7 @@ By default, when you click away from a modal, it will close itself. If you wish
use Filament\Actions\Action;
Action::make('updateAuthor')
- ->form([
+ ->schema([
// ...
])
->action(function (array $data): void {
@@ -609,6 +665,8 @@ Action::make('updateAuthor')
->closeModalByClickingAway(false)
```
+The `closeModalByClickingAway()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
If you'd like to change the behavior for all modals in the application, you can do so by calling `Modal::closedByClickingAway()` inside a service provider or middleware:
```php
@@ -617,7 +675,7 @@ use Filament\Support\View\Components\ModalComponent;
ModalComponent::closedByClickingAway(false);
```
-## Closing the modal by escaping
+### 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:
@@ -625,7 +683,7 @@ By default, when you press escape on a modal, it will close itself. If you wish
use Filament\Actions\Action;
Action::make('updateAuthor')
- ->form([
+ ->schema([
// ...
])
->action(function (array $data): void {
@@ -634,6 +692,8 @@ Action::make('updateAuthor')
->closeModalByEscaping(false)
```
+The `closeModalByEscaping()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
If you'd like to change the behavior for all modals in the application, you can do so by calling `Modal::closedByEscaping()` inside a service provider or middleware:
```php
@@ -642,7 +702,7 @@ use Filament\Support\View\Components\ModalComponent;
ModalComponent::closedByEscaping(false);
```
-## Hiding the modal close button
+### 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:
@@ -650,7 +710,7 @@ By default, modals have a close button in the top right corner. If you wish to h
use Filament\Actions\Action;
Action::make('updateAuthor')
- ->form([
+ ->schema([
// ...
])
->action(function (array $data): void {
@@ -659,6 +719,8 @@ Action::make('updateAuthor')
->modalCloseButton(false)
```
+The `modalCloseButton()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
If you'd like to hide the close button for all modals in the application, you can do so by calling `Modal::closeButton(false)` inside a service provider or middleware:
```php
@@ -675,7 +737,7 @@ By default, modals will autofocus on the first focusable element when opened. If
use Filament\Actions\Action;
Action::make('updateAuthor')
- ->form([
+ ->schema([
// ...
])
->action(function (array $data): void {
@@ -684,6 +746,8 @@ Action::make('updateAuthor')
->modalAutofocus(false)
```
+The `modalAutofocus()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
If you'd like to disable autofocus for all modals in the application, you can do so by calling `Modal::autofocus(false)` inside a service provider or middleware:
```php
@@ -696,7 +760,7 @@ ModalComponent::autofocus(false);
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:
+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;
@@ -716,13 +780,15 @@ Action::make('create')
->action(function (array $data): void {
// ...
})
- ->modalHidden(fn (): bool => $this->role !== 'admin')
+ ->modalHidden($this->role !== 'admin')
->modalContent(view('filament.pages.actions.create'))
```
+The `modalHidden()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
## Adding extra attributes to the modal window
-You may also pass extra HTML attributes to the modal window using `extraModalWindowAttributes()`:
+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;
@@ -730,3 +796,9 @@ use Filament\Actions\Action;
Action::make('updateAuthor')
->extraModalWindowAttributes(['class' => 'update-author-modal'])
```
+
+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.
+
+
diff --git a/packages/actions/docs/03-grouping-actions.md b/packages/actions/docs/03-grouping-actions.md
index 283b34d93f..011771c51b 100644
--- a/packages/actions/docs/03-grouping-actions.md
+++ b/packages/actions/docs/03-grouping-actions.md
@@ -2,6 +2,7 @@
title: Grouping actions
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -44,63 +45,6 @@ ActionGroup::make([
-### Setting the action group button icon
-
-You may set the [icon](../styling/icons) of the action group button using the `icon()` method:
-
-```php
-use Filament\Actions\ActionGroup;
-
-ActionGroup::make([
- // ...
-])->icon('heroicon-m-ellipsis-horizontal');
-```
-
-
-
-### Setting the action group button color
-
-You may set the color of the action group button using the `color()` method:
-
-```php
-use Filament\Actions\ActionGroup;
-
-ActionGroup::make([
- // ...
-])->color('info');
-```
-
-
-
-### Setting the action group button size
-
-Buttons come in 3 sizes - `sm`, `md` or `lg`. You may set the size of the action group button using the `size()` method:
-
-```php
-use Filament\Actions\ActionGroup;
-use Filament\Support\Enums\Size;
-
-ActionGroup::make([
- // ...
-])->size(Size::Small);
-```
-
-
-
-### Setting the action group tooltip
-
-You may set the tooltip of the action group using the `tooltip()` method:
-
-```php
-use Filament\Actions\ActionGroup;
-
-ActionGroup::make([
- // ...
-])->tooltip('Actions');
-```
-
-
-
## Setting the placement of the dropdown
The dropdown may be positioned relative to the trigger button by using the `dropdownPlacement()` method:
@@ -114,6 +58,8 @@ ActionGroup::make([
->dropdownPlacement('top-start')
```
+The `dropdownPlacement()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
## Adding dividers between actions
@@ -133,6 +79,8 @@ ActionGroup::make([
The `dropdown(false)` method puts the actions inside the parent dropdown, instead of a new nested dropdown.
+The `dropdown()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
## Setting the width of the dropdown
@@ -149,18 +97,7 @@ ActionGroup::make([
->dropdownWidth(Width::ExtraSmall)
```
-## 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')
-```
+The `dropdownWidth()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
## Controlling the dropdown offset
@@ -174,3 +111,20 @@ ActionGroup::make([
])
->dropdownOffset(16)
```
+
+The `dropdownOffset()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
+
+## 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')
+```
+
+The `maxHeight()` method also accepts a function to dynamically calculate the value. You can inject various utilities into the function as parameters.
diff --git a/packages/actions/docs/04-create.md b/packages/actions/docs/04-create.md
index af8e0a5cfa..d4b40c024d 100644
--- a/packages/actions/docs/04-create.md
+++ b/packages/actions/docs/04-create.md
@@ -1,6 +1,7 @@
---
title: Create action
---
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -11,8 +12,7 @@ use Filament\Actions\CreateAction;
use Filament\Forms\Components\TextInput;
CreateAction::make()
- ->model(Post::class)
- ->form([
+ ->schema([
TextInput::make('title')
->required()
->maxLength(255),
@@ -20,28 +20,6 @@ CreateAction::make()
])
```
-If you want to add this action to the header of a table, you may do so like this:
-
-```php
-use Filament\Actions\CreateAction;
-use Filament\Forms\Components\TextInput;
-use Filament\Tables\Table;
-
-public function table(Table $table): Table
-{
- return $table
- ->headerActions([
- CreateAction::make()
- ->form([
- TextInput::make('title')
- ->required()
- ->maxLength(255),
- // ...
- ]),
- ]);
-}
-```
-
## 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 `mutateFormDataUsing()` method, which has access to the `$data` as an array, and returns the modified version:
@@ -57,6 +35,8 @@ CreateAction::make()
})
```
+As well as `$data`, the `mutateDataUsing()` function can inject various utilities as parameters.
+
## Customizing the creation process
You can tweak how the record is created with the `using()` method:
@@ -73,6 +53,8 @@ CreateAction::make()
`$model` is the class name of the model, but you can replace this with your own hard-coded class if you wish.
+As well as `$data` and `$model`, the `using()` function can inject various utilities as parameters.
+
## Redirecting after creation
You may set up a custom redirect when the form is submitted using the `successRedirectUrl()` method:
@@ -96,6 +78,8 @@ CreateAction::make()
]))
```
+As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.
+
## Customizing the save notification
When the record is successfully created, a notification is dispatched to the user, which indicates the success of their action.
@@ -109,6 +93,8 @@ CreateAction::make()
->successNotificationTitle('User registered')
```
+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.
+
You may customize the entire notification using the `successNotification()` method:
```php
@@ -124,6 +110,8 @@ CreateAction::make()
)
```
+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.
+
To disable the notification altogether, use the `successNotification(null)` method:
```php
@@ -163,6 +151,8 @@ CreateAction::make()
})
```
+These hook functions can inject various utilities as parameters.
+
## 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:
@@ -201,7 +191,7 @@ $action->cancel();
## Using a wizard
-You may easily transform the creation process into a multistep wizard. Instead of using a `form()`, define a `steps()` array and pass your `Step` objects:
+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;
@@ -267,6 +257,8 @@ CreateAction::make()
->createAnother(false)
```
+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.
+
### 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:
@@ -296,3 +288,5 @@ use Filament\Actions\CreateAction;
CreateAction::make()
->preserveFormDataWhenCreatingAnother(fn (array $data): array => $data)
```
+
+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.
diff --git a/packages/actions/docs/05-edit.md b/packages/actions/docs/05-edit.md
index 5d8cbea8cd..240f39d27b 100644
--- a/packages/actions/docs/05-edit.md
+++ b/packages/actions/docs/05-edit.md
@@ -1,6 +1,7 @@
---
title: Edit action
---
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -11,8 +12,7 @@ use Filament\Actions\EditAction;
use Filament\Forms\Components\TextInput;
EditAction::make()
- ->record($this->post)
- ->form([
+ ->schema([
TextInput::make('title')
->required()
->maxLength(255),
@@ -20,28 +20,6 @@ EditAction::make()
])
```
-If you want to edit table rows, you may do so like this:
-
-```php
-use Filament\Actions\EditAction;
-use Filament\Forms\Components\TextInput;
-use Filament\Tables\Table;
-
-public function table(Table $table): Table
-{
- return $table
- ->actions([
- EditAction::make()
- ->form([
- TextInput::make('title')
- ->required()
- ->maxLength(255),
- // ...
- ]),
- ]);
-}
-```
-
## 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:
@@ -57,6 +35,8 @@ EditAction::make()
})
```
+As well as `$data`, the `mutateRecordDataUsing()` function can inject various utilities as parameters.
+
## 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 `mutateFormDataUsing()` method, which has access to the `$data` as an array, and returns the modified version:
@@ -72,6 +52,8 @@ EditAction::make()
})
```
+As well as `$data`, the `mutateDataUsing()` function can inject various utilities as parameters.
+
## Customizing the saving process
You can tweak how the record is updated with the `using()` method:
@@ -88,6 +70,8 @@ EditAction::make()
})
```
+As well as `$record` and `$data`, the `using()` function can inject various utilities as parameters.
+
## Redirecting after saving
You may set up a custom redirect when the form is submitted using the `successRedirectUrl()` method:
@@ -111,6 +95,8 @@ EditAction::make()
]))
```
+As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.
+
## Customizing the save notification
When the record is successfully updated, a notification is dispatched to the user, which indicates the success of their action.
@@ -124,6 +110,8 @@ EditAction::make()
->successNotificationTitle('User updated')
```
+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.
+
You may customize the entire notification using the `successNotification()` method:
```php
@@ -139,6 +127,8 @@ EditAction::make()
)
```
+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.
+
To disable the notification altogether, use the `successNotification(null)` method:
```php
@@ -178,6 +168,8 @@ EditAction::make()
})
```
+These hook functions can inject various utilities as parameters.
+
## 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:
diff --git a/packages/actions/docs/06-view.md b/packages/actions/docs/06-view.md
index e3adfe9a57..0f6ed2d3db 100644
--- a/packages/actions/docs/06-view.md
+++ b/packages/actions/docs/06-view.md
@@ -1,6 +1,7 @@
---
title: View action
---
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -11,8 +12,7 @@ use Filament\Actions\ViewAction;
use Filament\Forms\Components\TextInput;
ViewAction::make()
- ->record($this->post)
- ->form([
+ ->schema([
TextInput::make('title')
->required()
->maxLength(255),
@@ -20,28 +20,6 @@ ViewAction::make()
])
```
-If you want to view table rows, you may do so like this:
-
-```php
-use Filament\Actions\ViewAction;
-use Filament\Forms\Components\TextInput;
-use Filament\Tables\Table;
-
-public function table(Table $table): Table
-{
- return $table
- ->actions([
- ViewAction::make()
- ->form([
- TextInput::make('title')
- ->required()
- ->maxLength(255),
- // ...
- ]),
- ]);
-}
-```
-
## 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:
@@ -56,3 +34,5 @@ ViewAction::make()
return $data;
})
```
+
+As well as `$data`, the `mutateRecordDataUsing()` function can inject various utilities as parameters.
diff --git a/packages/actions/docs/07-delete.md b/packages/actions/docs/07-delete.md
index 3f433c80f8..b7f4877f8b 100644
--- a/packages/actions/docs/07-delete.md
+++ b/packages/actions/docs/07-delete.md
@@ -1,6 +1,7 @@
---
title: Delete action
---
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -10,25 +11,9 @@ Filament includes an action that is able to delete Eloquent records. When the tr
use Filament\Actions\DeleteAction;
DeleteAction::make()
- ->record($this->post)
```
-If you want to add this action to a row of a table, you may do so like this:
-
-```php
-use Filament\Actions\DeleteAction;
-use Filament\Tables\Table;
-
-public function table(Table $table): Table
-{
- return $table
- ->actions([
- DeleteAction::make()
- ]);
-}
-```
-
-Or if you want to add it as a table bulk action, so that the user can choose which rows to delete, they can use `Filament\Actions\DeleteBulkAction`:
+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;
@@ -54,6 +39,8 @@ DeleteAction::make()
->successRedirectUrl(route('posts.list'))
```
+As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.
+
## Customizing the delete notification
When the record is successfully deleted, a notification is dispatched to the user, which indicates the success of their action.
@@ -67,6 +54,8 @@ DeleteAction::make()
->successNotificationTitle('User deleted')
```
+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.
+
You may customize the entire notification using the `successNotification()` method:
```php
@@ -82,6 +71,8 @@ DeleteAction::make()
)
```
+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.
+
To disable the notification altogether, use the `successNotification(null)` method:
```php
@@ -106,3 +97,5 @@ DeleteAction::make()
// ...
})
```
+
+These hook functions can inject various utilities as parameters.
diff --git a/packages/actions/docs/08-replicate.md b/packages/actions/docs/08-replicate.md
index d90995c71c..be3b69f1a0 100644
--- a/packages/actions/docs/08-replicate.md
+++ b/packages/actions/docs/08-replicate.md
@@ -1,6 +1,7 @@
---
title: Replicate action
---
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -10,23 +11,6 @@ Filament includes an action that is able to [replicate](https://laravel.com/docs
use Filament\Actions\ReplicateAction;
ReplicateAction::make()
- ->record($this->post)
-```
-
-If you want to replicate table rows, you may do so like this:
-
-```php
-use Filament\Actions\ReplicateAction;
-use Filament\Tables\Table;
-
-public function table(Table $table): Table
-{
- return $table
- ->actions([
- ReplicateAction::make(),
- // ...
- ]);
-}
```
## Excluding attributes
@@ -66,17 +50,7 @@ ReplicateAction::make()
->successRedirectUrl(route('posts.list'))
```
-If you want to redirect using the replica, use the `$replica` parameter:
-
-```php
-use Filament\Actions\ReplicateAction;
-use Illuminate\Database\Eloquent\Model;
-
-ReplicateAction::make()
- ->successRedirectUrl(fn (Model $replica): string => route('posts.edit', [
- 'post' => $replica,
- ]))
-```
+As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.
## Customizing the replicate notification
@@ -91,6 +65,8 @@ ReplicateAction::make()
->successNotificationTitle('Category replicated')
```
+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.
+
You may customize the entire notification using the `successNotification()` method:
```php
@@ -106,6 +82,17 @@ ReplicateAction::make()
)
```
+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.
+
+To disable the notification altogether, use the `successNotification(null)` method:
+
+```php
+use Filament\Actions\RestoreAction;
+
+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.
@@ -126,6 +113,8 @@ ReplicateAction::make()
})
```
+These hook functions can inject various utilities as parameters.
+
## Halting the replication process
At any time, you may call `$action->halt()` from inside a lifecycle hook, which will halt the entire replication process:
diff --git a/packages/actions/docs/09-force-delete.md b/packages/actions/docs/09-force-delete.md
index 1b94f9a8e5..64256c3591 100644
--- a/packages/actions/docs/09-force-delete.md
+++ b/packages/actions/docs/09-force-delete.md
@@ -1,6 +1,7 @@
---
title: Force-delete action
---
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -10,25 +11,9 @@ Filament includes an action that is able to force-delete [soft deleted](https://
use Filament\Actions\ForceDeleteAction;
ForceDeleteAction::make()
- ->record($this->post)
```
-If you want to add this action to a row of a table, you may do so like this:
-
-```php
-use Filament\Actions\ForceDeleteAction;
-use Filament\Tables\Table;
-
-public function table(Table $table): Table
-{
- return $table
- ->actions([
- ForceDeleteAction::make()
- ]);
-}
-```
-
-Or if you want to add it as a table bulk action, so that the user can choose which rows to force delete, they can use `Filament\Actions\ForceDeleteBulkAction`:
+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;
@@ -54,6 +39,8 @@ ForceDeleteAction::make()
->successRedirectUrl(route('posts.list'))
```
+As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.
+
## 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.
@@ -67,6 +54,8 @@ ForceDeleteAction::make()
->successNotificationTitle('User force-deleted')
```
+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.
+
You may customize the entire notification using the `successNotification()` method:
```php
@@ -82,6 +71,8 @@ ForceDeleteAction::make()
)
```
+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.
+
To disable the notification altogether, use the `successNotification(null)` method:
```php
@@ -106,3 +97,5 @@ ForceDeleteAction::make()
// ...
})
```
+
+These hook functions can inject various utilities as parameters.
diff --git a/packages/actions/docs/10-restore.md b/packages/actions/docs/10-restore.md
index a80b36536b..f5cb4f4504 100644
--- a/packages/actions/docs/10-restore.md
+++ b/packages/actions/docs/10-restore.md
@@ -1,6 +1,7 @@
---
title: Restore action
---
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -10,25 +11,9 @@ Filament includes an action that is able to restore [soft deleted](https://larav
use Filament\Actions\RestoreAction;
RestoreAction::make()
- ->record($this->post)
```
-If you want to add this action to a row of a table, you may do so like this:
-
-```php
-use Filament\Actions\RestoreAction;
-use Filament\Tables\Table;
-
-public function table(Table $table): Table
-{
- return $table
- ->actions([
- RestoreAction::make()
- ]);
-}
-```
-
-Or if you want to add it as a table bulk action, so that the user can choose which rows to restore, they can use `Filament\Actions\RestoreBulkAction`:
+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;
@@ -54,6 +39,8 @@ RestoreAction::make()
->successRedirectUrl(route('posts.list'))
```
+As well as `$record`, the `successRedirectUrl()` function can inject various utilities as parameters.
+
## Customizing the restore notification
When the record is successfully restored, a notification is dispatched to the user, which indicates the success of their action.
@@ -67,6 +54,8 @@ RestoreAction::make()
->successNotificationTitle('User restored')
```
+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.
+
You may customize the entire notification using the `successNotification()` method:
```php
@@ -82,6 +71,8 @@ RestoreAction::make()
)
```
+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.
+
To disable the notification altogether, use the `successNotification(null)` method:
```php
@@ -106,3 +97,5 @@ RestoreAction::make()
// ...
})
```
+
+These hook functions can inject various utilities as parameters.
diff --git a/packages/actions/docs/11-import.md b/packages/actions/docs/11-import.md
index 0949efcd06..89b0c2501d 100644
--- a/packages/actions/docs/11-import.md
+++ b/packages/actions/docs/11-import.md
@@ -1,6 +1,8 @@
---
title: Import action
---
+import Aside from "@components/Aside.astro"
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -24,9 +26,13 @@ php artisan vendor:publish --tag=filament-actions-migrations
php artisan migrate
```
-> If you're using PostgreSQL, make sure that the `data` column in the notifications migration is using `json()`: `$table->json('data')`.
+
-> If you're using UUIDs for your `User` model, make sure that your `notifiable` column in the notifications migration is using `uuidMorphs()`: `$table->uuidMorphs('notifiable')`.
+
You may use the `ImportAction` like so:
@@ -161,6 +167,8 @@ ImportColumn::make('sku')
Any rows that do not pass validation will not be imported. Instead, they will be compiled into a new CSV of "failed rows", which the user can download after the import has finished. The user will be shown a list of validation errors for each row that failed.
+As well as allowing a static value, the `rules()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
### Casting state
Before [validation](#validating-csv-data), data from the CSV can be cast. This is useful for converting strings into the correct data type, otherwise validation may fail. For example, if you have a `price` column in your CSV, you may want to cast it to a float:
@@ -181,9 +189,13 @@ ImportColumn::make('price')
})
```
+As well as `$state`, the `castStateUsing()` method allows you to inject various utilities into the function as parameters.
+
In this example, we pass in a function that is used to cast the `$state`. This function removes any non-numeric characters from the string, casts it to a float, and rounds it to two decimal places.
-> Please note: if a column is not [required by validation](#validating-csv-data), and it is empty, it will not be cast.
+
Filament also ships with some built-in casting methods:
@@ -233,6 +245,8 @@ ImportColumn::make('price')
})
```
+As well as `$state`, the `castStateUsing()` method allows you to inject various utilities into the function as parameters.
+
### Handling multiple values in a single column
You may use the `multiple()` method to cast the values in a column to an array. It accepts a delimiter as its first argument, which is used to split the values in the column into an array. For example, if you have a `documentation_urls` column in your CSV, you may want to cast it to an array of URLs:
@@ -244,6 +258,8 @@ ImportColumn::make('documentation_urls')
->multiple(',')
```
+As well as allowing a static value, the `multiple()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
In this example, we pass in a comma as the delimiter, so the values in the column will be split by commas, and cast to an array.
#### Casting each item in an array
@@ -272,6 +288,8 @@ ImportColumn::make('customer_ratings')
->nestedRecursiveRules(['integer', 'min:1', 'max:5'])
```
+As well as allowing a static value, the `nestedRecursiveRules()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
### Importing relationships
You may use the `relationship()` method to import a relationship. At the moment, `BelongsTo` and `BelongsToMany` relationships are supported. For example, if you have a `category` column in your CSV, you may want to import the category `BelongsTo` relationship:
@@ -332,6 +350,8 @@ ImportColumn::make('author')
})
```
+The function passed to `resolveUsing` allows you to inject various utilities into the function as parameters.
+
If you are using a `BelongsToMany` relationship, the `$state` will be an array, and you should return a collection of records that you have resolved:
```php
@@ -383,6 +403,7 @@ If you want to customize how column state is filled into a record, you can pass
```php
use App\Models\Product;
+use Filament\Actions\Imports\ImportColumn;
ImportColumn::make('sku')
->fillRecordUsing(function (Product $record, string $state): void {
@@ -390,12 +411,14 @@ ImportColumn::make('sku')
})
```
+The function passed to the `fillRecordUsing()` method allows you to inject various utilities into the function as parameters.
+
### Adding helper text below the import column
Sometimes, you may wish to provide extra information for the user before validation. You can do this by adding `helperText()` to a column, which gets displayed below the mapping select:
```php
-use Filament\Forms\Components\TextInput;
+use Filament\Actions\Imports\ImportColumn;
ImportColumn::make('skus')
->multiple(',')
@@ -621,6 +644,8 @@ ImportAction::make()
->maxRows(100000)
```
+As well as allowing a static value, the `maxRows()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
## Changing the import chunk size
Filament will chunk the CSV, and process each chunk in a different queued job. By default, chunks are 100 rows at a time. You can change this by calling the `chunkSize()` method on the action:
@@ -634,7 +659,11 @@ ImportAction::make()
->chunkSize(250)
```
-If you are encountering memory or timeout issues when importing large CSV files, you may wish to reduce the chunk size.
+As well as allowing a static value, the `chunkSize()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
+
## Changing the CSV delimiter
@@ -649,6 +678,8 @@ ImportAction::make()
->csvDelimiter(';')
```
+As well as allowing a static value, the `csvDelimiter()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
You can only specify a single character, otherwise an exception will be thrown.
## Changing the column header offset
@@ -664,6 +695,8 @@ ImportAction::make()
->headerOffset(5)
```
+As well as allowing a static value, the `headerOffset()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
## Customizing the import job
The default job for processing imports is `Filament\Actions\Imports\Jobs\ImportCsv`. If you want to extend this class and override any of its methods, you may replace the original class in the `register()` method of a service provider:
@@ -822,6 +855,8 @@ ImportAction::make()
]),
```
+As well as allowing a static value, the `fileRules()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
## Lifecycle hooks
Hooks may be used to execute code at various points within an importer's lifecycle, like before a record is saved. To set up a hook, create a protected method on the importer class with the name of the hook:
diff --git a/packages/actions/docs/12-export.md b/packages/actions/docs/12-export.md
index 91a1dabab1..b3a48c9b65 100644
--- a/packages/actions/docs/12-export.md
+++ b/packages/actions/docs/12-export.md
@@ -1,6 +1,8 @@
---
title: Export action
---
+import Aside from "@components/Aside.astro"
+import UtilityInjection from "@components/UtilityInjection.astro"
## Introduction
@@ -22,9 +24,13 @@ php artisan vendor:publish --tag=filament-actions-migrations
php artisan migrate
```
-> If you're using PostgreSQL, make sure that the `data` column in the notifications migration is using `json()`: `$table->json('data')`.
+
-> If you're using UUIDs for your `User` model, make sure that your `notifiable` column in the notifications migration is using `uuidMorphs()`: `$table->uuidMorphs('notifiable')`.
+
You may use the `ExportAction` like so:
@@ -159,6 +165,8 @@ ExportColumn::make('amount_including_vat')
})
```
+As well as `$record`, the `state()` function can inject various utilities as parameters.
+
### Formatting the value of an export column
You may instead pass a custom formatting callback to `formatStateUsing()`, which accepts the `$state` of the cell, and optionally the Eloquent `$record`:
@@ -170,6 +178,8 @@ ExportColumn::make('status')
->formatStateUsing(fn (string $state): string => __("statuses.{$state}"))
```
+As well as `$state`, the `formatStateUsing()` function can inject various utilities as parameters.
+
If there are [multiple values](#exporting-multiple-values-in-a-cell) in the column, the function will be called for each value.
#### Limiting text length
@@ -183,6 +193,8 @@ ExportColumn::make('description')
->limit(50)
```
+As well as allowing a static value, the `limit()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
#### Limiting word count
You may limit the number of `words()` displayed in the cell:
@@ -194,6 +206,8 @@ ExportColumn::make('description')
->words(10)
```
+As well as allowing a static value, the `words()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
#### Adding a prefix or suffix
You may add a `prefix()` or `suffix()` to the cell's value:
@@ -206,6 +220,8 @@ ExportColumn::make('domain')
->suffix('.com')
```
+As well as allowing static values, the `prefix()` and `suffix()` methods also accept functions to dynamically calculate them. You can inject various utilities into the functions as parameters.
+
### Exporting multiple values in a cell
By default, if there are multiple values in the column, they will be comma-separated. You may use the `listAsJson()` method to list them as a JSON array instead:
@@ -476,6 +492,8 @@ ExportAction::make()
])
```
+As well as allowing a static value, the `options()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
Now, you can access the data from these options inside the exporter class, by injecting the `$options` argument into any closure function. For example, you might want to use it inside `formatStateUsing()` to [format a column's value](#formatting-the-value-of-an-export-column):
```php
@@ -561,7 +579,11 @@ ExportAction::make()
->chunkSize(250)
```
-If you are encountering memory or timeout issues when exporting large CSV files, you may wish to reduce the chunk size.
+As well as allowing a static value, the `chunkSize()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
+
## Changing the CSV delimiter
@@ -574,6 +596,8 @@ public static function getCsvDelimiter(): string
}
```
+As well as allowing a static value, the `csvDelimiter()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
+
You can only specify a single character, otherwise an exception will be thrown.
## Customizing XLSX files
diff --git a/packages/actions/src/ActionGroup.php b/packages/actions/src/ActionGroup.php
index f725055a83..2dc23127e1 100644
--- a/packages/actions/src/ActionGroup.php
+++ b/packages/actions/src/ActionGroup.php
@@ -329,7 +329,16 @@ class ActionGroup extends ViewComponent implements Arrayable, HasEmbeddedView
protected function resolveDefaultClosureDependencyForEvaluationByName(string $parameterName): array
{
return match ($parameterName) {
- 'record' => [$this->getRecord()],
+ 'livewire' => [$this->getLivewire()],
+ 'model' => [$this->getModel() ?? $this->getSchemaContainer()?->getModel() ?? $this->getSchemaComponent()?->getModel()],
+ 'mountedActions' => [$this->getLivewire()->getMountedActions()],
+ 'record' => [$this->getRecord() ?? $this->getSchemaContainer()?->getRecord() ?? $this->getSchemaComponent()?->getRecord()],
+ 'schema' => [$this->getSchemaContainer()],
+ 'schemaComponent', 'component' => [$this->getSchemaComponent()],
+ 'schemaOperation', 'context', 'operation' => [$this->getSchemaContainer()?->getOperation() ?? $this->getSchemaComponent()?->getContainer()->getOperation()],
+ 'schemaGet', 'get' => [$this->getSchemaComponent()->makeGetUtility()],
+ 'schemaComponentState', 'state' => [$this->getSchemaComponent()->getState()],
+ 'table' => [$this->getTable()],
default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName),
};
}
diff --git a/packages/actions/src/DeleteAction.php b/packages/actions/src/DeleteAction.php
index 74655111bf..2d294b16c1 100644
--- a/packages/actions/src/DeleteAction.php
+++ b/packages/actions/src/DeleteAction.php
@@ -48,7 +48,7 @@ class DeleteAction extends Action
});
$this->action(function (): void {
- $result = $this->process(static fn (Model $record) => $record->delete());
+ $result = $this->process(static fn (Model $record): ?bool => $record->delete());
if (! $result) {
$this->failure();
diff --git a/packages/actions/src/ForceDeleteAction.php b/packages/actions/src/ForceDeleteAction.php
index cd9f628ab1..ef895e0d47 100644
--- a/packages/actions/src/ForceDeleteAction.php
+++ b/packages/actions/src/ForceDeleteAction.php
@@ -36,7 +36,7 @@ class ForceDeleteAction extends Action
$this->modalIcon(FilamentIcon::resolve('actions::force-delete-action.modal') ?? Heroicon::OutlinedTrash);
$this->action(function (): void {
- $result = $this->process(static fn (Model $record) => $record->forceDelete());
+ $result = $this->process(static fn (Model $record): ?bool => $record->forceDelete());
if (! $result) {
$this->failure();
diff --git a/packages/actions/src/Imports/ImportColumn.php b/packages/actions/src/Imports/ImportColumn.php
index 859b41f2ac..0a64d694fd 100644
--- a/packages/actions/src/Imports/ImportColumn.php
+++ b/packages/actions/src/Imports/ImportColumn.php
@@ -316,10 +316,7 @@ class ImportColumn extends Component
return $this;
}
- /**
- * @param array $options
- */
- public function castState(mixed $state, array $options): mixed
+ public function castState(mixed $state): mixed
{
$originalState = $state;
@@ -336,7 +333,6 @@ class ImportColumn extends Component
return $this->evaluate($this->castStateUsing, [
'originalState' => $originalState,
'state' => $state,
- 'options' => $options,
]);
}
diff --git a/packages/actions/src/Imports/Importer.php b/packages/actions/src/Imports/Importer.php
index 133045fcb8..3bd127c2c4 100644
--- a/packages/actions/src/Imports/Importer.php
+++ b/packages/actions/src/Imports/Importer.php
@@ -139,10 +139,7 @@ abstract class Importer
continue;
}
- $this->data[$columnName] = $column->castState(
- $this->data[$columnName],
- $this->options,
- );
+ $this->data[$columnName] = $column->castState($this->data[$columnName]);
}
}
diff --git a/packages/actions/src/RestoreAction.php b/packages/actions/src/RestoreAction.php
index d43d736219..e8c137de4d 100644
--- a/packages/actions/src/RestoreAction.php
+++ b/packages/actions/src/RestoreAction.php
@@ -44,7 +44,7 @@ class RestoreAction extends Action
return;
}
- $result = $this->process(static fn () => $record->restore());
+ $result = $this->process(static fn (): ?bool => $record->restore());
if (! $result) {
$this->failure();
diff --git a/packages/schemas/docs/01-overview.md b/packages/schemas/docs/01-overview.md
index e8e6632cdf..3290dc43b7 100644
--- a/packages/schemas/docs/01-overview.md
+++ b/packages/schemas/docs/01-overview.md
@@ -82,7 +82,6 @@ use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Section;
-use Filament\Schemas\Schema;
$schema
->components([
diff --git a/packages/schemas/docs/05-wizards.md b/packages/schemas/docs/05-wizards.md
index fa8654f97a..bc33682358 100644
--- a/packages/schemas/docs/05-wizards.md
+++ b/packages/schemas/docs/05-wizards.md
@@ -32,7 +32,7 @@ Wizard::make([
## Rendering a submit button on the last step
diff --git a/packages/tables/docs/03-filters/06-layout.md b/packages/tables/docs/03-filters/06-layout.md
index 2e0ef8d491..9a04b3556c 100644
--- a/packages/tables/docs/03-filters/06-layout.md
+++ b/packages/tables/docs/03-filters/06-layout.md
@@ -177,4 +177,4 @@ public function table(Table $table): Table
}
```
-In this example, we have put two of the filters inside a [section](../../schemas/layouts/section) component, and used the `columns()` method to specify that the section should have two columns. We have also used the `columnSpanFull()` method to specify that the section should span the full width of the filter form, which is also 2 columns wide. We have inserted each filter into the form schema by using the filter's name as the key in the `$filters` array.
+In this example, we have put two of the filters inside a [section](../../schemas/sections) component, and used the `columns()` method to specify that the section should have two columns. We have also used the `columnSpanFull()` method to specify that the section should span the full width of the filter form, which is also 2 columns wide. We have inserted each filter into the form schema by using the filter's name as the key in the `$filters` array.