Call to a member function getKey() on null
Hi,
I am trying to use a custom class to create a record. According to the documentation,
https://filamentphp.com/docs/3.x/actions/prebuilt-actions/create#customizing-the-creation-process
"$model is the class name of the model, but you can replace this with your own hard-coded class if you wish."
That's why I'm using it like this:
In my class, I make many calls and writes to the database. The operations execute correctly, however, I get an error at the end:
I read somewhere that the function should return a Model, but in my case in ->using() many operations are executed on the database, so how to return one model?
I am trying to use a custom class to create a record. According to the documentation,
https://filamentphp.com/docs/3.x/actions/prebuilt-actions/create#customizing-the-creation-process
"$model is the class name of the model, but you can replace this with your own hard-coded class if you wish."
That's why I'm using it like this:
->using(function ($livewire, array $data, Tables\Actions\CreateAction $action): Void {
WhdocMovesClass::move($data, $livewire, $action);
}) In my class, I make many calls and writes to the database. The operations execute correctly, however, I get an error at the end:
Call to a member function getKey() on nullI read somewhere that the function should return a Model, but in my case in ->using() many operations are executed on the database, so how to return one model?
Solution
Your using() must return a model in CreateAction, that's just baked in. It's CreateAction. It exists to create a model. There is other internal housekeeping done after the process() call that runs your using(), which requires the created model.
If that doesn't fit your needs, then you probably just need to use a custom Action, rather than modifying CreateAction.
If that doesn't fit your needs, then you probably just need to use a custom Action, rather than modifying CreateAction.
