problem saving pivot table
I have 3 tables: this is my code
https://gist.github.com/elmudometal/9ad07fafda4c692e7f453501ddf313a9
3 Replies
this is my error:
It really is not clear what you are trying to do. You have aa pivot with 3 foreign ID's. Your main repeater() relationship is not named, so will default to 'ordenes', but I don't see a relation with that name on your model. Then you have a multiple select within your repeater which seems to be trying to use another relationship.
Maybe take a step back and exaplain exactly what you are trying to achieve?
It is a registration system where a registration can have many categories but at the same time it has payment order registrations:
1 registration has many categories
1 registration has many payment orders
but for example:
1 payment order has 2 categories and another payment order has 1 category
This results in:
1 registration with 3 categories
All this logic for the user view is created but I can't get it to filament
The models have all their relationships, I just cut them out because they are very long.
My idea was to create a registration form and this adds a repeat of orders and in the orders I added the categories (this one as select multiple) but since the registration has not yet been created I do not have the id so when saving everything it fails in this relationship multi foreign
My solution was to create a pivot model and assign the id
class OrdenCategoria extends Pivot
{
protected static function booted(): void
{
static::creating(function ($ordenCategoria) {
if (empty($ordenCategoria->inscripcion_id)) {
$ordenCategoria->inscripcion_id = $ordenCategoria?->pivotParent?->inscripcion_id;
}
});
}
}