Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I name my pivot table which contains a two word table?

I would like to use Laravel 5.0 many to many relationship and as we know the naming convention is alphabetically joining the two table names... But what if one of the tables is a two word name itself?

For example we have "sub_categories" and "products" tables.

Should the pivot table name be: "product_sub_category"?


And yes I know that we can specify the table name as the second argument when we specify our relationship in our models: $this->belongsToMany('App\Product', 'table_pivot');

But I wanna know if there's a naming convention for this too! So that we can simply leave the second argument and follow the standard conventions...

like image 884
Ali Avatar asked Nov 02 '15 07:11

Ali


1 Answers

You can name as you want, and specify the table name as the 2nd param on the relationship call in your models:

return $this->belongsToMany('Model', 'table_name');

Official Documentation

like image 172
Froxz Avatar answered Oct 24 '22 20:10

Froxz