Laravel Creating model

Source: Internet
Author: User
Tags using git

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.