The previous article has introduced the development environment of the building, if there are problems can leave a message after the article.
This article will be developed from the actual project, step by step to understand the laravel framework.
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 ' and ' = ', ' ,
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:
<?phpuse Illuminate\database\schema\blueprint;use Illuminate\database\migrations\migration;class Createtablenametable extends Migration {/** * Run the migrations. * @return void */public function up () { }/** * Reve RSE 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://v4.golaravel.com/docs/4.1/schema
1<?PHP2 3 UseIlluminate\database\schema\blueprint;4 Useilluminate\database\migrations\migration;5 6 classCreatetablenametableextendsMigration {7 8 /**9 * Run the migrations.Ten * One * @return void A */ - Public functionUp () - { theSchema::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 '); A $table-timestamps (); at }); - -Schema::create (' comments ',function(Blueprint$table) { - $table->increments (' id '); - $table->unsignedinteger (' post_id '); - $table-string(' Commenter '); in $table-string(' Email '); - $table->text (' comment '); to $table-Boolean(' Approved '); + $table-timestamps (); - }); the *Schema::table (' Users ',function(Blueprint$table) { $ $table-Create ();Panax Notoginseng $table->increments (' id '); - $table-string(' username '); the $table-string(' Password '); + $table-string(' Email '); A $table-string(' Remember_token ', +)nullable (); the $table-timestamps (); + }); - } $ $ /** - * Reverse the migrations. - * the * @return void - */Wuyi Public functionDown () the { -Schema::d rop (' posts '); Wu -Schema::d rop (' comments '); About $Schema::d rop (' users '); - } - -}
Continue to enter PHP artisan migrate in the command window above to perform the migration
More about migration: http://v4.golaravel.com/docs/4.1/migrations
Just write it down here, and continue tomorrow.
. NET to PHP laraval Framework Learning Series (ii) Project Combat---Models