I concerned about auto naming tables in many-to-many Laravel relationship.
for example:
Schema::create('feature_product', function (Blueprint $table) {
when change the table name to:
Schema::create('product_feature', function (Blueprint $table) {
I have an error in my relationship.
What's the matter with product_feature
?
Laravel's naming convention for pivot tables is singularized table names in alphabetical order separated by an underscore. So, if one table is
features
, and the other table isproducts
, the pivot table will befeature_product
.You are free to use any table name you want (such as
product_feature
), but you will then need to specify the name of the pivot table in the relationship. This is done using the second parameter to thebelongsToMany()
function.