In Laravel, the convention for naming pivot tables is to use the singular form of the related table names, ordered alphabetically and separated by an underscore. However, when dealing with specific table names like glasses_products and glasses_categories, you can follow a similar approach but adapt it to your specific naming needs.
For your scenario, you have two specific tables: glasses_products and glasses_categories. The pivot table should ideally reflect the relationship between these two tables. A good naming convention would be to use the singular form of each specific table name, ordered alphabetically.
In this case, the singular forms would be glasses_product and glasses_category. Alphabetically, glasses_category comes before glasses_product, so the pivot table name would be:
glasses_category_glasses_product
However, if you find this name too verbose or if it doesn't fit well with your application's naming conventions, you can choose a more concise name that still clearly represents the relationship, such as glasses_category_product.
Remember, Laravel's Eloquent allows you to specify the pivot table name explicitly in your relationship methods if you deviate from the default naming convention. You can do this using the ->using() method or by specifying the table name directly in the belongsToMany method:
public function glassesProducts()
{
return $this->belongsToMany(GlassesProduct::class, 'glasses_category_glasses_product');
}
This way, you maintain clarity in your database schema while still adhering to Laravel's flexibility.