Home > Mobile >  Laravel table pivot nomenclature
Laravel table pivot nomenclature

Time:12-22

I have a menu table, a group menu and a pivot table for this table.

menus
menu_groups
menu_menu_group or menu_group_menu?

Is correct this nomenclature?

Thanks!

CodePudding user response:

It is based on the class names of the models. It gets the class basenames (class name) of each Model and converts them to snake case:

Str::snake(class_basename($modelInstance));

After it gets an array of the 2 names then it calls sort:

sort($segments);

Then it implodes that array, joining it by an underscore, and makes sure its lowercase:

return strtolower(implode('_', $segments));

So if your classes are Menu and MenuGroup then the pivot by convention would be: menu_menu_group.

CodePudding user response:

The correct name based on Laravel models will be menu_menu_groups

  • Related