The previous article has introduced the development environment of the building, this article will be developed from the actual project, step by step to understand the laravel framework. First, let's look at the model of the next Laravel framework (Models)
Models is the first step in developing an MVC project.
Let's start with the modeling.
1. Entity Relationship Diagram,
Because I don't know what PHP has a good modeling tool, I used the VS ADO entity Model data Modeling
The following begins the Laravel encoding, before encoding, the first to configure the database connection, in the app/config/database.php file
' MySQL ' = array (' driver ' = ' mysql ', ' read ' = = Array ( ' host ' = ' 127.0.0.1:3306 ' ), ' write ' = = Array ( ' host ' = ' 127.0.0.1:3306 ' ), ' database ' = ' test ', ' username ' = ' Root ', ' password ' = ' root ', ' charset ' = ' utf8 ', ' collation ' = ' utf8_unicode_ci ', ' Prefix ' = ', '),
Once configured, you need to use the artisan tool, which is a PHP command tool in the Laravel directory
First you need to build a migration migrate through artisan, which is almost identical to ASP.
In the Laravel directory shfit+ right-click to open the Command window input artisan migrate:make create_xxxx will generate a migration file with a timestamp prefix under the app/database/migrations file
Code:
<?php use Illuminate\database\schema\blueprint;use illuminate\database\migrations\migration; Class Createtablenametable extends Migration { /** * Run the migrations. * * @return void * * Public function up () { } /** * Reverse the migrations. * * @return void * /Public Function down () { }}
See here is the entityframework migration experience basically found this is surprisingly similar ah.
The next step is to create our entity structure, and the Laravel structure generator can refer to the http://www.php.cn/
<?phpuse Illuminate\database\schema\blueprint;use Illuminate\database\migrations\migration;class Createtablenametable extends Migration {/** * Run the migrations. * * @return void */Public function up () {schema::create (' posts ', function (Blueprint $table) {$table->increments (' id '); $table->unsignedinteger (' user_id '); $table->string (' title '); $table->string (' Read_more '); $table->text (' content '); $table->unsignedinteger (' Comment_count '); $table->timestamps (); }); Schema::create (' Comments ', function (Blueprint $table) {$table->increments (' id '); $table->unsignedinteger (' post_id '); $table->string (' commenter '); $table->string (' email '); $table->text (' comment '); $table->boolean (' approved '); $table->timestamps (); }); Schema::table (' Users ', function (Blueprint $table) {$table->create (); $table->increments (' id '); $table->string (' username '); $table->string (' password '); $table->string (' emAil '); $table->string (' Remember_token ', +)->nullable (); $table->timestamps (); }); }/** * Reverse the migrations. * * @return void */Public function down () {Schema::d rop (' posts '); Schema::d rop (' comments '); Schema::d rop (' users '); }}
Continue to enter PHP artisan migrate in the command window above to perform the migration