Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I name an Eloquent polymorphic table?

I'm using Laravel eloquent to design my database. Eloquent has a naming convention for naming a many to many polymorphic relations. If the initial table's name is comments, then the pivot table should be named commentable. If it is documents, then documentable and so on.

But how should I name my pivot table if the source table is companies?

like image 856
Warrio Avatar asked Oct 12 '25 09:10

Warrio


1 Answers

The convention is as you described, but Laravel doesn't force you into that naming convention. You're free to use whatever name you'd like as long as you make note of that in the model relationship like :

public function tags()
{
    return $this->morphToMany('App\Tag', 'taggable');
}

That being said, the convention would probably say you should write "companyable", as weird as that sounds.

like image 195
Arty Avatar answered Oct 14 '25 05:10

Arty