Override Model for Create/EditAction?
Shouldnt this work? This is for individual HeaderActions in a Table that is based of the User model, but I want to create an entry in a different model (well my action() will create some aspects in User as well). Anyway, when I launch the form, it says
Call to undefined method App\Models\User::lead_source()
and thats because its trying to load it in the User class and not the PropertyManager class that i specified with ->model()
. Are my assumptions incorrect?8 Replies
try
->form(fn ($form) => $form->schema(...)->model(...))
Thanks. That worked!
hmm, I spoke too soon. Guess i cant attach ->fillForm() or action(), etc to that anonymous $form
obviously if i do something like it never gets there. $record is always null, so I tried and thats when i get the
Method Filament\Forms\Form::fillForm does not exist.
errorfillForm() is just a shortcut
you add it after form(), not inside it
I get that, but couldn’t get any values to the form, always got null when I did it normally..I think I had failed in my example. I know obviously the record is for the User Table and I’m creating/editing a record for a different model, so have to somehow handle that too.
im honestly not sure if you should be extending CreateAction like this
if youre not creating the model associated with the table
Maybe I’m overthinking it. Basically a Users Table and Users have a relation of Property Managers and that’s also a ->role attribute. Im launching a different form based on the role. I also have a Property Managers table on another page. Im simply trying to share the form schema with the two different tables. I know they would have to be filled/saved a bit differently, but figured it would still be doable
I already have different edit/create actions for different roles and it’s working great, this is just the only one that is initiated from two different tables. Hope that is making a bit more sense
how would a tableHeaderActions have access to $record? IINM the $record in your action closure likely the record after your create action saved the data..
@wychoong header would not, thats obviously for just creation, EditActions on table rows obviously do