How to name the model name for the "users_transactions" table in Laravel? It would be more correct to call: UserTransaction? or UsersTransaction? or UserTransactions?

  • I create the Users directory and there I go to the Transactions class. But you can and so. - Naumov

2 answers 2

The Laravel developers themselves say to create tables in the plural, and models in the single, then the models will not need to specify the table, the framework will find it based on the model name, if you specify not by their rules, then you will need to explicitly specify the table name.

In your case it will be correct:

Table Name: user_transactions

Model Name: UserTransaction

    You can provide the linking of the model name and the table to the framework itself. If you run this command:

     php artisan make:model UserTransaction -m 

    then the project will create a file with the model class, and a migration file for the table whose name will conform to the Laravel rules ( user_transactions ).