Header Ads

ad728

Laravel tutorial

Introduction

This QuestStart Guide provides a basic introduction to the Lariol framework and includes content on database migration, sophisticated ORM, routing, validation, comments and sheet templates. This is an excellent starting point if it is generally new in the larval framework or the PHP framework. If you have already used Laurel or other PHP frameworks, you can check one of our latest QuestStars.

To test the basic selection of larval characteristics, we will create a simple task list that we can use to track all the tasks we want to perform (for example, example of "task list"). The complete and ready source code for this project is available on GitHub.


Installation

Of course, you will first need a new installation of the Laravel framework. You can use the Homestate virtual machine of your choice or the local PHP environment to run the framework. Once your local environment is ready, you can install the larval frame using Composer:

Create laravel composer project / laravel quick start - prefer-dist
You are read only for the rest of this QuestStart. However, if you want to download the Quest Start source code and run it on your local machine, you can install your dependency by cloning your Git repository:

Gut Clone https://github.com/laravel/quickstart-basic quickstart
Quest Start CD
Install Composer
PHP artisans migrate
For more complete documentation on the construction of a local larval development environment, see the complete documentation for the home, home study and installation.


Create a database


Database Migration
First, use migration to define a database table to avoid all your tasks. The Larival Database migration flow provides an easy way to define the structure and modifications of the database table using expressive PHP code. Instead of manually telling your team members to manually add columns to a local copy of their database, their peers can easily execute the migrations they have in the source control.

Then, we create a database table in which all our work will be done. Artisan CLI can be used to create a variety of classes and will save you a lot of typing when you create your Lariol projects. In this case, let's use the mac: migration command to create a new database migration for our task table:

PHP Mac Articles: Migrate create_tasks_table --create = work
The migration will be placed in the database / migration directory of your project. As you have noticed, the mac: migration command has already added the automatic increment identification and the timestamp to the migration file. Let's edit this file and add an additional string column to our job name:

<? PHP

Use Illuminate \ Database \ Schema \ Blueprint.
Aluminate \ database \ migration \ migrate

ClassCreat task table boosted migration
{
/ **
* Execute the transition.
* *
* @ Empty empty
* /
Public event ()
{
Schema :: Create ('Tasks', Function (plan $ table)) {
$ Table-> increase ('ID');
$ Table-> string ('name');
$ Table-> timestamp ();
});
}

/ **
* Reverse the migration.
* *
* @ Empty empty
* /
Inactive public function ()
{
Scheme :: Drop ('Task');
}
}
To execute our migration, we will use the transfer artsan command. If you are using Homestead, you must execute this command from your virtual machine, since your host machine will not have direct access to the database.

PHP artisans migrate

This command will create all our database tables. If you examine the database tables using the database client of your choice, you should see a new task table that contains the columns specified in our migration. Then, we are ready to praise the clear and precise model of our actions!


Healthy model

The feature is the default Laravel ORM (object mapper). It is virtually impossible to retrieve and store data in your database using explicitly defined "models." In general, each talented model corresponds directly to the same database table.

So, let's define a task model that is compatible with our task database table that we just created. Again, we can use a craft command to create this model. In this case, we will use the mac: model command.

Create PHP craftsman: model task

The model will be placed in the application directory of your application. By default, the model class is empty. We do not need to explicitly explain to the Alevant model which table it matches because it will assume that the database table is a composite form of the model name. Therefore, in this case, it is assumed that the task model conforms to the table of

No comments

Post Bottom Ad

ad728