The previous article has introduced the establishment of the development environment. This article will learn about the laravel framework step by step from the practical development of the project. First, let's take a look at the laravel framework model (Models)
The previous article has introduced the establishment of the development environment. This article will learn about the laravel framework step by step from the practical development of the project. First, let's take a look at the laravel framework model (Models)
When developing an mvc project, models is the first step.
Next we will start with modeling.
1. Object relationship diagram,
I don't know what php has to do with modeling tools. Here I use vs ado.net object model data modeling.
The following code starts laravel. Before encoding, you must configure the database connection in the app/config/database. php file.
'Mysql' => array ('driver '=> 'mysql', 'read' => array ('host' => '2017. 0.0.1: 3306 ',), 'write' => array ('host' => '2017. 0.0.1: 3306 '), 'database' => 'test', 'username' => 'root', 'Password' => 'root ', 'charset' => 'utf8', 'colation' => 'utf8 _ unicode_ci ', 'prefix' => '',),
After configuration, you need to use the artisan tool. This is a php command tool in the laravel directory.
First, you need to create a migration migrate through artisan, which is almost the same as asp.net mvc.
In the laravel directory, right-click shfit + and enter artisan migrate: make create_XXXX in the open command window. A migration file with a timestamp prefix is generated in 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 () {}/*** Reverse the migrations. ** @ return void */public function down (){}}
The entityframework migration experience is surprisingly similar.
The next step is to create our object structure. For details about laravel's structure generator, refer
<? 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 ('apache'); $ 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', 100) -> nullable (); $ table-> timestamps () ;});}/*** Reverse the migrations. ** @ return void */public function down () {Schema: drop ('posts'); Schema: drop ('comments'); Schema :: drop ('users ');}}
Enter php artisan migrate in the preceding command window to execute migration.
More migration knowledge:
Write it here. Continue tomorrow.