
Excluding Table Names from Laravel's Many-to-Many Relations
This article was originally published on bmf-tech.com . When designing many-to-many relationships, I thought I was following the documentation, but I had a slight misunderstanding. Here are three tables, right? The tables in this case: events event_tags event_tag_event ← pivot table For normal tables: events tags tag_event You would typically set up the relationship according to the default conventions, but when using slightly unconventional names, there are some things to be cautious about. Let's take a look at the documentation Laravel 5.1 Eloquent: Relationships Ah, so I just need to provide a second argument! public function eventTags () { // The second argument is the Pivot table! return $this -> belongstoMany ( 'App\Modles\EventTag' , 'event_tag_event' ) -> withTimestamps (); } public function events () { return $this -> belongsToMany ( 'App\Models\Events' ); } When I launched tinker to check... SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias on rel
Continue reading on Dev.to
Opens in a new tab


