Override Model for Create/EditAction?

Shouldnt this work?
->form(fn() => PropertyManager::getForm())
->model(PropertyManager::class)
->form(fn() => PropertyManager::getForm())
->model(PropertyManager::class)
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
Dan Harrin
Dan Harrin2y ago
try ->form(fn ($form) => $form->schema(...)->model(...))
Mark Chaney
Mark ChaneyOP2y ago
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
->form(fn ($form) => $form->schema(PropertyManager::getForm())->model(PropertyManager::class))
->fillForm($record->toArray())
->form(fn ($form) => $form->schema(PropertyManager::getForm())->model(PropertyManager::class))
->fillForm($record->toArray())
it never gets there. $record is always null, so I tried
->form(fn ($form,$record) => $form->schema(PropertyManager::getForm())->model(PropertyManager::class)->fillForm($record->toArray()))
->form(fn ($form,$record) => $form->schema(PropertyManager::getForm())->model(PropertyManager::class)->fillForm($record->toArray()))
and thats when i get the Method Filament\Forms\Form::fillForm does not exist. error
Dan Harrin
Dan Harrin2y ago
fillForm() is just a shortcut you add it after form(), not inside it
Mark Chaney
Mark ChaneyOP2y ago
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.
Dan Harrin
Dan Harrin2y ago
im honestly not sure if you should be extending CreateAction like this if youre not creating the model associated with the table
Mark Chaney
Mark ChaneyOP2y ago
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
wyChoong
wyChoong2y ago
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..
Mark Chaney
Mark ChaneyOP2y ago
@wychoong header would not, thats obviously for just creation, EditActions on table rows obviously do
Want results from more Discord servers?
Add your server