Database and Model laravel framework

1. Database file .env is located
Here Insert Picture Description
above the frame of the database is arranged laravel
red box indicates that the name of the database table
2. The model
<1> defined position Here Insert Picture Description
Here Insert Picture Description
<2> Name Model
laravel frame for defining the model is not strictly, in the form of a table name (capitalized) .php's
Note: the model name you want to have associated with the database table name
and because it is associated with the database can not sub-directory management, put their name each table so there is no separate the need for sub-directory management
<3> to create the model
created by the form of the command line
php artisan make: model Member
Here Insert Picture Description
Here Insert Picture Descriptionwill be created as models, above is the model has been successfully created
<4> Notes on defining the model
Here Insert Picture Description
Here Insert Picture Description
3.DB class in the controller the use of
DB class is a class frame provided by the database operation, the database table can operate all
steps of:
introducing class DB (DB use)
Here Insert Picture Description
using the DB class DB :: table (table)
test
Here Insert Picture Description
output
Here Insert Picture Descriptionmay also be used operating table model
" 1. "introduction member class
Here Insert Picture Description
" 2 "there are two ways to use
<1> facade DB using the same mode of operation, in order to call the static method based form, this form of model does not require Examples of, for example:
Member: GET () :: Table equivalent to DB ( 'Member') -> GET ()
<2> Examples of models and then to use the class
For example: $ Model = new new Member ();
$ Model-> GET ();
selection criteria in two ways;
1. If the frame is carrying laravel method chosen arbitrarily
2. If you define a method, the choice of two kinds

Released nine original articles · won praise 0 · Views 308

Guess you like

Origin blog.csdn.net/Ya_Tou945/article/details/105148305