create and attach related models when creating resource
Hi there. First time trying/looking into filament to replace some of my own solution.
I have a Team model with hasmany relation to Uniform model.
I’m just wondering if it’s possible somehow from the Team create page to also create an amount of uniform models at the same time.
Any pointers to relevant docs or anything appreciated. Looking forward to diving in to this.
Solution:Jump to solution
Just checked again. Repeater works with HasMany. So best to use a repeater: https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-an-eloquent-relationship
4 Replies
You could use a Repeater and store that data yourself. I think Repeater only supports BelongsToMany not HasMany, might be wrong though
Thanks dennis. for this id like to create an amount of generic uniform items (this could be a field in the form).
If im correct, i would need to start here -
https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-the-creation-process
1) Create the team
2) Create X number of uniforms and attach them to the team
$team->saveMany($uniforms)
3) return the Team
Does that sound right?Solution
Just checked again. Repeater works with HasMany. So best to use a repeater: https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-an-eloquent-relationship
Thanks. il start there.
appreciate it