Using protected properties on form actions
Is it safe to store a protected property on a form action?
5 Replies
I was trying to do the same with action arguments but I'm running into an issue where the arguments are not always preserved across Livewire requests:
Maybe I misunderstood the purpose of action arguments 😅
I think @Mark Chaney may have some insight on this. I remember him battling action arguments, but I never really understood what was going on.
Arguments aren’t preserved. They have to be passed each time the action is called because they are part of the livewire callback method.
If that makes sense.
And you can use protected properties. They just won’t be exposed to the front end. So you can’t use them in your views.
If you need default arguments though you can define them in the set up method with ->arguments()
Ah, that makes sense. I hit this in my Maps plugin, with an action I call from JS with:
$wire.mountAction('markerAction', {model_id: marker.model_id})
... which opens an Infolist modal, getting the record with record(function ($argument) { ... }). Worked fine opening the modal, but when the modal is closed, Filament calls record() again with no $arguments. Easy fix, I just nullsafe my code in record(), but I was kinda confused as to why it got called on close with no $arguments.Great, that fits my use-case quite well. I'm just trying to provide an "API" to the user of the Action to preconfigure it in the Form. I'm accessing the values only within
->action()
.
Thank you both 🙂