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

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;
            });
    }

}


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 !
Solution
OOOOOhhhh !!!

->form(function (array $arguments) {
                return [...]

form can have a function ... !!!!

THX a lot 😁
Was this page helpful?