Sylfel
Sylfel
FFilament
Created by Sylfel on 3/8/2024 in #❓┊help
CreateAction with arguments
Hi, i try to use CreateAction with arguments in my own Livewire component. Here a extract of my code : blade template :
@foreach ($categories as $category)
[...]
{{ ($this->addToCategoryAction)(['category' => $category->id]) }}
@endforeach
@foreach ($categories as $category)
[...]
{{ ($this->addToCategoryAction)(['category' => $category->id]) }}
@endforeach
component :
class Dashboard extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

public function addToCategoryAction(): Action
{
return CreateAction::make('addToCategory')
->model(Note::class)
->form([
TextInput::make('label')
->required(function (): bool {
// here i would like to use argument "category"
})
->maxLength(255),
])
->mutateFormDataUsing(function (array $data, array $arguments): array {
// here i have access to arguments !
return $data;
});
}

}
class Dashboard extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

public function addToCategoryAction(): Action
{
return CreateAction::make('addToCategory')
->model(Note::class)
->form([
TextInput::make('label')
->required(function (): bool {
// here i would like to use argument "category"
})
->maxLength(255),
])
->mutateFormDataUsing(function (array $data, array $arguments): array {
// here i have access to arguments !
return $data;
});
}

}
How can i use argument in required (or Select or ...) in formmethod ? Is it possible to loadCategory Model once, and use it in different sub-method in make method ? Thanks a lot !
14 replies