Bind different model to action form
I've created action with form that I am calling from some resource edit page. Model binded to that action form is the model that belongs to the resource from which I am calling that action. What I want is to bind completely different model to that action form that have no relation to underlying model. Any ideas how to do that.
Example what I would like to do:
And that action button is called from PageResource edit page that is why I am creating Filament\Components\Actions\Action. My form in action is in no relation to a underlying Page model, and I want to be bind to Product model.
7 Replies
I did found a solution to my problem but only partially.
In my Page resource edit page I've added ViewField component that includes my custom Livewire component that contain CreateAction button to create new product. I've managed to do that, to render the button properly but when I click on it nothing happens. I expect to open modal form.
In ViewField blade template I am just rendering my custom Livewire component:
This is my custom Livewire component that has CreateAction button:
And livewire component template:
Why when clicking on the button, modal window with form is not opening? Can someone help me with this one?
Maybe you can try this:
The thing is that my Product has a lot of relationship fields that I need to handle, that is why I need CreateAction as that would handle all of the nested relationships. And I would like to position button for creating a new product inside form that, so that is why I am using custom Livewire component.
The CreateAction button is rendering properly on the page, but when I click on it spinner appear and then disappear and that's it.
Move the action below the form in the action order
I am not sure I understand what I need to do?
Try the above
Can you explain in your example what is CreateProduct.php? In my scenario I want to use CreateAction to create Product in the PageResource. That is what I want to achieve. I want to open modal for creating Product from PageResource.
I would like to implement that button inside PageResource edit form. I will try to put that Action in the header if it is not possible to add it inside the form.
In my example CreateProduct.php is custom livewire component that I am calling in Filament\Forms\ViewField component in the PageResource form