[Laravel5.2 documentation] Getting Started Guide-simple task management system 1. Introduction
The quick start guide will provide a basic introduction to the Laravel framework, including database migration, Eloquent ORM, routing, verification, views, and Blade templates. If you are a newbie to Laravel or even a stranger to the PHP framework, this will be a good start point for you. If you have used Laravel to obtain other PHP frameworks, you can jump to the Advanced Guide ).
To demonstrate the basic use of Laravel features, we will build a simple List of tasks (To-Do List) for tracking all tasks To be completed ), the complete code for this tutorial has been published on Github: https://github.com/laravel/quickstart-basic.
2. Installation
Install Laravel
Before you start, you must install a new Laravel application. You can use the Homestead virtual machine or the local PHP development environment to run applications. After setting up the development environment, you can use the following Composer command to install the application:
composer create-project laravel/laravel quickstart --prefer-dist
Install the Quickstart project
Of course, you can also clone the GitHub repository to install it locally:
git clone https://github.com/laravel/quickstart-basic quickstartcd quickstartcomposer installphp artisan migrate
If you do not know how to build a local development environment, refer to Homestead and installation documentation.
3. prepare the database 3.1 for database migration
First, let's use migration to define data tables for processing all tasks. Laravel's database migration feature provides a simple way to define and modify the data table structure: each member of the team does not need to add columns to the local database, you can create and modify data tables by simply running the migration task submitted to the source code control.
Let's create a data table that processes all tasks. The Artisan command can be used to generate multiple types to save repetitive work. In this example, we use the make: migration command to generate the data table migration for tasks:
php artisan make:migration create_tasks_table --create=tasks
The migration file generated by this command is located in the database/migrations directory under the root directory of the project. you may have noticed that make: the migration command has added the auto-increment ID and timestamp to the migration file. next we will edit the file to add more columns to the data table tasks:
increments('id'); $table->string('name'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('tasks'); }}
To run the migration, run the Artisan command migrate. If you are using Homestead, you should run this command in the virtual machine:
php artisan migrate
This command will create all the data tables defined in the migration file for us. if you use the database client software to view the database, you can see that a new tasks table has been created, it contains the columns we define in the migration. Next, we are going to define a Eloquent ORM model for this data table.
3.2 Eloquent model
Laravel uses the default ORM of Eloquent. The model of Eloquent makes data access simple and easy. Generally, each Eloquent model has a corresponding data table.
Therefore, we need to define a Task model corresponding to the created tasks table. Similarly, we use the Artisan command to generate this model:
php artisan make:model Task
This model class is located in the app Directory. by default, the model class is empty. We do not need to tell which data table the Eloquent model corresponds to. we mentioned this in the Eloquent document, the corresponding data table is tasks by default, and the empty model class is shown below:
Understanding