The followingLaravelframework tutorial column will introduce to you the importance of specifying table names in Laravel. I hope it will be helpful to friends in need!
Since Laravel will automatically associate the corresponding table name when creatingModel
, the specific process for encountering problems is as follows:
After entering the following command in Terminal, acustomer.php
file
Appdirectory. However, it needs to be added to the database by default. The table is customers instead of customers, which means that the system will automatically add the plural "s" according to the name of the Model. In general, there is no problem here, but if you encounter things such as person changing to people or various things that our Chinese people cannot easily distinguish. Form, so affordable will cause problems for our development; in addition, it is also possible that we do not want the system to automatically match the database, but to customize the table name.
What we need to do is actually very simple. Add a rule specifying the table name in the created Model file function:
As above, we addedprotected $table = 'customer';
, force the database corresponding tocustomer.php
to be designated ascustomer
instead of the system defaultcustomers
. We can also see this in the User.php that comes with the framework. In order for the program to run stably and without errors, this step should be applied in everyModel
.
If you encounter a problem, simply record it...
The above is the detailed content of Finally know the importance of specifying table names in Laravel. For more information, please follow other related articles on the PHP Chinese website!