It has been used in the CI framework. Recently learning to use the Laravel framework to summarize some of the problems encountered is a record for later invocation. In addition, I want to be able to meet the same problem with the help of friends.
The Laravel database table is generated according to the program written by Laravel, which makes it easy to manage the entire project using GIT and other version number controls.
To establish the User_address model as an example to record:
1 php artisan make:model User_address
. Create a model using commands.
2. After success, the program folder app and Database/migrations will generate two files respectively.
3. Open the file generated under Database/migrations, this file is the file that controls the generation of database tables. The contents are as follows:
-_06_02_071328_create_user_addresses_table.The code in PHP:<?Phpuse Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;class Createuseraddressestable extends Migration {/** * Run the migrations. * * @return void * * Publicfunction up () {Schema:: Create(' user_addresses ', Function (Blueprint$table) {$table -Increments (' address_id ') -Comment"PRIMARY Key");$table -Mediuminteger (' user_id ') -Comment' User ID ');$table -string(' Consignee ', -) -Comment' Consignee ');$table -string(' Country ', -) -Comment' Country ');$table -string(' province ', -) -Comment' Provinces ');$table -string(' City ', -) -Comment' City ');$table -string(' District ', -) -Comment' Street ');$table -string(' Address ', -) -Comment' specific address ');$table -string(' Zip_Code ', -) -Comment' Political Code mail ');$table -string(' Tel ', -) -Comment' fixed phone ');$table -string(' Mobile ', -) -Comment' cell phone ');$table -Tinyinteger (' Is_default ') -Comment' is the default address '); }); }/** * Reverse the migrations. * * @return void * * Publicfunction down () {Schema::d ROP(' addresses '); }}
4. Run: php artisan migrate
command to generate table user_address in the database.
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Laravel Creating model