Laravel is known as the "All-stack" framework because it handles everything from Web services to database management and HTML generation, and the vertically integrated Web development environment provides a better experience for developers.
Developers can build and manage laravel project environments through command-line tools. Laravel comes with a Artisan
well-known command-line tool that provides some useful commands for the development process, which can be used to generate framework code and database management. It was developed based on the powerful Symfony Console component.
The goal of Laravel is to create a pleasant development process for developers without sacrificing the functionality of the application. Happy developers can create the best code! For this purpose, we have the strength to focus on laravel, which is even based on the development of languages or tools such as Ruby on Rails, ASP. NET MVC, and Sinatra.
Laravel is easy to understand and powerful, and it provides powerful tools for developing large, robust applications. Outstanding IOC, database migration tools, and tightly integrated unit test support that give you the ability to build any application.
Directory structure
This is where all laravel projects have essentially the same directory structure, where each file has a specified place. Make sure that you work in a "laravel" way by agreeing on the directory structure.
As you can see, there are 4 folders under the Laravel project:,,, app
bootstrap
public
vendor
These 4 folders have a lot of subfolders underneath, when you first see such a rich folder content, do you feel very stressed? It's okay, we'll get to know the different folders individually.
app
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 in this directory.
bootstrap
It is used to store the files needed for the system to boot, and these files are called by files such as index.php.
public
This folder is the only Web server directory that the outside world can see. It contains the Laravel framework core boot file index.php, which can also be used to store any public static resources, such as css,javascript,images, etc.
vender
App Catalog
As mentioned above, all the interesting things in Laravel are generated in the app directory, so we can learn more about what's inside.
As we can see from the table above, we can get a structured application with good file system as long as we spend some effort on creating and naming files.
Model-View-controller (MVC)
Let's take a deeper look at how to build laravel applications. You may have noticed that there are three subdirectories under the app directory: Models,views,controllers. This indicates that Laravel is the Model-view-controller (MVC) schema pattern, which separates the "business logic" from the input and display logic (GUI) associated with the graphical user interface. In Laravel Web applications, business logic is usually made up of data models (such as users, blog posts), and the GUI is just a page in a browser. The MVC design pattern is very popular in the field of web development.
Three elements of the MVC pattern:
- Models (model)
- Views (view)
- Controllers (Controller)
Laravel's response process
A typical Laravel application consists of the MVC mentioned above
When a laravel application is accessed, the browser sends a request that is received by the Web server and passed to the Laravel routing engine. After the Laravel router receives the request, it redirects the method to the appropriate controller class according to the configuration.
Then the controller class takes over. In some cases, the controller renders a view immediately, which is a template that will be converted to HTML and sent back to the browser. A more general Dynamic Web site, the controller interacts with the model to communicate 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 advocates models, views and controllers that should be kept completely separate from the storage of separate files in different directories. This is where Laravel's directory structure works.
Design patterns like MVC are created to make it easier for developers to work. This is where laravel is more powerful than PHP without any model. If this discussion you are now feeling very abstract, do not worry! When you start working with Laravel, 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 establishes the business logic of the application. Each piece of data is represented by using 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:
Select AllCopyput it in your notes .
ClassPersonExtendseloquent{PublicfunctionMother() {Return$this->belongsto (' mother '); }PublicfunctionFather() {Return$this->belongsto (' Father '); }Publicfunction spouse () {return $this->hasone ( Span class= "hljs-string" > ' spouse '); } public function sisters () {return $ This->hasmany ( ' Sister ');} public function brothers () {return $this->hasmany ( ' Brother ');}}
(EXT)
Laravel architecture of the framework