BelongsToMany relationship in Repeater
Hey, I've got two models - Ad & Location. The Location model uses a custom primary key
$table->string('ekatte')->primary();
. Those are both relationships:
When trying to edit an Ad and insert more records using a Repeater with a relationship set, it fails with an error that the property location_ekatte
must be added to the $fillable array in the Location model. That property doesn't even exist there... You can check the attached file.
I really appreciate any help you can provide.10 Replies
Lol, im such a dummy, thanks
@Dan Harrin Sorry to bother you again, but I slept on the issue and figured that HasMany may not be appropriate. The reason is that I have predefined Locations and want to attach multiple to the Ad. For me, that would be done with a pivot table holding the ad_id and the location_ekatte. I think the problem is in the naming of the fields in the pivot table.
the hasmany is to the pivot table
you can still use a belongstomany for the main relationship
you just need a hasmany for the repeater so we know which table to write data to
Right after I posted my second answer tried with a HasMany as you just suggested. Works like a charm! Thanks for you time!
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
@n3b0r Sure, you just have to add a HasMany to a model that represents the pivot.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Thats the repeater
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Glad you found the issue! Keep it up mate.