Call the "edit" modal for a record in a resource from a different page
Hi everyone. I have a "Reservation" Resource (and Model) that I use in a custom Livewire component to create a custom reservation calendar for a restaurant (Image attached). I'd like to be able to call the edit modal when I click on a reservation in the calendar, but I can't find the right way.
- This link taught me about the mountable actions : - https://github.com/filamentphp/filament/blob/3.x/packages/actions/docs/06-adding-an-action-to-a-livewire-component.md
- A few other searches here on discord taught me about the necessity to have a form but I can't seem to get the form schema directly from my resource ;
- I already have the
<x-filament-actions::modals />
call in my livewire component ;
- I've searched and searched the github repo directly but searches get messy as they return help pages and tests, sometimes in contexts using the same nomenclature ("mountAction" for example).
Can anyone point me in a direction that would allow me to call a "edit" method (or action) on my livewire component that wound return the modal and form of a normal "EditAction" for the resource and that I can pass my model to ?
Thank youSolution:Jump to solution
To anyone looking for a possible way to do this, I managed to do it by inferring code from @awcodes' "Quick Create" plugin :
1 / In your custom Livewire component add uses :
```use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
[...]...
2 Replies
Solution
To anyone looking for a possible way to do this, I managed to do it by inferring code from @awcodes' "Quick Create" plugin :
1 / In your custom Livewire component add uses :
2 / When you mount the component, bind the actions (here through a
getActions()
method which calls a getModelInstance()
to pass the ID in the blade view :
3/ In your component blade view, include the modals :
<x-filament-actions::modals />
4/ On every button or element where you need to bind a createAction
, add this :
5/ Same thing on every button or element where you want to bind an editAction
but with the ID passed :
And it ... kinda just works π See captures attached.
Of course, this is a very straightforward version with hardcoded names (as it suits my needs here) but check https://github.com/awcodes/filament-quick-create/blob/3.x/src/QuickCreatePlugin.php for a more flexible way of doing this.
(Ping @Zep Fietje, here is the explanation ! )