PHP Laravel Installation Tutorials Learning Notes

Source: Internet
Author: User

PHP Laravel Installation Tutorials Learning Notes

With all the environment in place, of course you have to start to understand the framework.

Standing on the shoulders of giants, learning things will be more effective. I found a good article online that just makes it easy for me to understand the architecture of the Laravel application. So borrowed directly to use.

This chapter is translated from "Architecture of Laravel Applications", all copyright is the original author, because the original author wrote this article Laravel version has not reached 4.1, some places slightly different, I will make a slight change.

Original Stable Host, LLC (I don't know if we've got it right)

Translation Bowen Huang


Laravel is called the "All-stack" framework because it handles everything from network services to database management until HTML is generated, and a vertically integrated web development environment provides a better experience for developers.

A typical programmer interacts with Laravel through command-line tools to build and manage the Laravel project environment. Laravel comes with an excellent command-line tool called Artisan, which can be used to generate framework code and database schemas, artisan can handle everything from database schema migration to resource and configuration management.
Conventions better than configuration

One of the interesting features of Laravel is that it prescribes some pretty serious restrictions on how to build a Web application. Surprisingly, these restrictions make it easier to create apps--much easier. Let's see why.

Laravel differs from other vertically integrated development environments in that its strong preference conventions are better than configurations. While some java,python or PHP frameworks often require a large amount of XML configuration, Laravel rarely needs to be configured at the outset (perhaps only a few lines in PHP). This circumvention of configuration files makes them very unique, and the code structures that are recognized in all Laravel applications are the same.
A project structure to govern them all!

It's not surprising that all laravel projects have essentially the same directory structure-where each file has its designated location. This agreed-upon catalog result ensures that the developer works in the "Laravel Way".

Figure 1.1 shows what the Laravel project directory structure looks like:

Laravel Study Notes (ii) architecture of the Laravel application

Figure 1.1 Laravel Project directory structure

As you can see, Laravel contains only 4 folders below, these 4 folders have sub-folders below, this rich subfolder at the first time see is there a pressure? I'll introduce it one by one. Most of our development work will be done under the app/folder.

Here's a basic description of each folder and file:

Top-level folders



Contains the site's controllers (Controller), models (model), Views (view), and assets (resources). These are the main code that runs the site, and you spend most of your time on them.


It is used to store the files needed for the system to boot, and these files are called by files such as index.php.


This folder is the only thing visible to the outside world and is the directory that must point to your Web server. It contains the Laravel framework core boot file index.php, this directory can also be used to store any public static resources, such as css,javascript,images.


Used to store all third-party code in a typical Laravel application, this includes Laravel source code and its associated plugins, and contains additional pre-packaged features.

As mentioned above,/app is the place where all the fun is generated, let's take a deeper look at the structure of this directory.

Figure 1.2 shows the details of the/app folder:

Laravel Study Notes (ii) architecture of the Laravel application

Figure 1.2 App folder details

Here is a detailed description:

folder for files



Configure the application's runtime rules, database, session, and so on. Contains a large number of configuration files that are used to change various aspects of the framework. Most of the options returned in the configuration file are associated with the PHP array.


Various application-level settings, instant zones, locales (locales), debug modes, and unique encryption keys.


Controls how authentication is done in the application, that is, the authentication driver.


If your application uses caching to speed up response times, configure the feature here.


Here you can specify some additional classes to contain the compiled files claimed by the ' artisan optimize ' command. These should be classes that are included in basically every request to the application.


Contains the relevant configuration information for the database, which is the default database engine and connection information.


The configuration file for the e-mail sender engine, the SMTP server, from: the header


Control Laravel How to manage user sessions, that is, session driver, session lifetime.


Miscellaneous configuration of the template system.


Contains the controller classes that provide basic logic, data model interaction, and view files that load applications.


Contains PHP classes that allow Laravel to update the schema of the current database while maintaining synchronization of all versions of the database. Migration files are generated using the Artisan tool.


Contains PHP files that allow the Artisan tool to populate database tables with relational data.


A PHP file that contains an array of strings that make the application easy to localize. By default, the directory contains the English language for pagination and the language lines for form validation.


A model is a class of rules that represent the information (data) of an application and manipulate data. In most cases, each table in the database corresponds to a model in the app. Most of the application business logic will be concentrated in the model.


Contains custom settings related to the Artisan tool and global and local contexts.


This directory stores laravel temporary files for various services, such as session, cache, compiled view templates. This directory must be writable on the Web server. This directory is maintained by Laravel and we can not care.


This folder provides you with a convenient location for unit testing. If you use PHPUnit, you can use the Artisan tool to perform all tests at once.


This folder contains the HTML templates that the controller or route uses. Please note that you can only place template files under this folder. Other static resource files such as CSS, JavaScript, and images files should be placed under the/public folder.


This is the routing file for your application, which contains routing rules that tell Laravel how to connect incoming requests to the closure functions, controllers, and operations of route processing. The file also contains several event declarations, including error pages, that can be used to define the composers of the view.


This file contains various application and route filtering methods that are used to change the results of your application. Laravel has some pre-defined filters for access control and XSS protection.

It took a lot of thought. In creating and naming folders, you get an application with a good file system.

Here's what you get: MVC
Model-View-controller (MVC)

Let's go into the high-level overview of Laravel application work. You may have noticed that the standard Laravel application structure consists of an application directory app/, which contains three subdirectories: models/,views/and controllers/. This reveals that Laravel follows the Model-view-controller (MVC) architecture pattern, which is forcing the "business logic" of input to demonstrate a logical relationship to be separate from the graphical user interface (GUI). As far as Laravel Web applications are concerned, business logic is usually made up of data models such as users and blog posts. The GUI is just a Web page in a browser. The MVC design pattern is very popular in the field of web development.

3 Components of the MVC pattern:

Models (model)

Views (view)

Controllers (Controller)

[note] The original author here details the MVC three components, I here because of space is not introduced.
Laravel components

A typical Laravel application contains the MVC components mentioned above, such as:

Laravel Study Notes (ii) architecture of the Laravel application

When interacting with Laravel, the browser sends a request and the Web server receives the request and passes it to the Laravel routing engine. The Laravel route receives the request and then redirects the appropriate controller class method to the route-based URL pattern.

Then the controller class takes over. In some cases, the controller immediately renders a view, which is a template that is converted to HTML and sent back to the browser. A more common dynamic site, the controller interacts with the model, which is a PHP object that represents an element in an application (such as a user, blog post) and is responsible for communicating with the database. After the model is called, the controller renders the final view (HTML,CSS and images) and returns the full Web page to the user's browser.

Laravel promotes the notion that models, views, and controllers should be kept fairly independent by storing these elements in separate code files in different directories. This is how the LARAVEL directory structure works.

Design patterns like MVC are created to make life easier for developers. This is where laravel is more powerful than PHP without any model. If this discussion is abstract, now, don't worry! When you start laravel work, you will not realize that you are working in a design mode. After a while, it will become natural.
Data model

The data model is the foundation of any application, and it describes the business logic of the application. Any piece of data is represented by a database table. Laravel provides a number of techniques to simplify access to the database.

Laravel connects the data model and database tables of the application by turning table rows in the database into PHP objects that can be manipulated easily. It also enables you to execute business rules that describe the relationships between different data models in your application, and so on. For example, a person's family relationship can be described with laravel eloquent or/m as follows:

 1 class Person extends eloquent 2 {3     public Function mother () 4     {5          return $this->belongsto (' mother '); 6    } 7  8     public Function father () 9     {10& nbsp;        return $this->belongsto (' Father ');11    } 13     Public Function Spouse () 14     {15          return $this->hasone (' spouse ');16    }17 18     Public Function Sisters () 19     {20         return $ This->hasmany (' Sister ');21    }22 23     Public Function () 24      {25         return $this->hasmany (' Brother ');26    }27}

If there is anything wrong with the translation, please refer to it.
Manuscripts: Diligent Learning
To be Continued ...

Extended reading:

Laravel Study Notes (ii) architecture of the Laravel application: Http://
Laravel Study Notes (iii) Database Database migration: Http://
Select the Laravel framework version you need to know: Http://
10 you need to know Laravel 5.3 new features:
Implementation of the Laravel Pipeline component: Http://
[Laravel 5.3 New features]-routing related modifications:
10 x Laravel 5 Program Optimization tips:

PHP Laravel Installation Tutorials Learning Notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.