Custom CreateAction in getHeaderActions redirects to Createpage of Resource
I try to make a CreateAction on a Resource to create a record of a different model.
This worked in Filamentphp 3.
I updated to Filamentphp 4 and now this is not working any more.
To not trap into some self-made problems like cache i created a new app from scratch with FilamentPHP 4.
Now i stripped everything down and have a Foo and a Bar Model with Resources and i addes a CreateAction to ViewBar.php:
So this is the exact example vom https://filamentphp.com/docs/4.x/actions/create#introduction
It should show a form with the field "title" when i click on it but the "new bar" button links to http://127.0.0.1:8001/admin/bars/create?record=1 and shows me the form to create a new Bar record
The code from my original app is this:
But it does the same -> redirect to the Create-Form of the Resource i put it in...
Am i doing something wrong?
Thank you.
Solution:Jump to solution
ok i think we are getting closer.
maybe i'm a little disapointed because it was super intuitive in v3 and now just different 😉
this works:
```php...
6 Replies
I think calling the createAction natively does that. Just instead do an Action
Thank you for your suggestion. Good idea but it only woks if i use a form without relations.
If i use this:
I get an error "The relationship [invoice] does not exist on the model [App\Models\Todo]."
So it still hangs on Todo model and somehow the ->model() method is not working
Off the top of my head Can you try ->record(null) on the action and ->fillForm([])
Does seem bug worthy report that, since an action that defines a model should use that model class and not the current resource model... Wonder if action picks up Record or form fill hence my suggesiton above
it looks like this but that does not work:
Still just redirects me to the create form of the resource where i use this
I'll upload an app to reproduce this and test on a page outside a resource tomorrow and then... open an issue?
You shouldn’t have to define a record, fillform or model for this. It’s just an action with a form and you handle the creation in the action call back.
Could be a weird situation too where the order of the method chain matters.
Solution
ok i think we are getting closer.
maybe i'm a little disapointed because it was super intuitive in v3 and now just different 😉
this works:
booking has a relationship to invoice.
but: when i remove the record() it tries to resolve this for the resource, i'm in (ToDo) which results in an error that there is no such relationship
i can live with this. thanks everybody for helping.
if i can figure out to use CreateAction for this again, i'll come back here 🙂