In 20 1 1 year, Taylor Otwell first brought Laleville to this world. At that time, Laravel was a brand-new modern framework. Laravel is based on MVC architecture, which can meet various needs such as event handling and user authentication. At the same time, modular and extensible code is realized through package management, which has strong support for database management.
No matter you are an expert or a novice, once you come into contact with Laravel, you will have a feeling of short meeting-this is exactly the framework you are looking for for for PHP projects. In this article, we will discuss why Laravel has become the most successful and popular PHP framework.
Modularization &; expansibility
Laravel is modular and extensible. You can find any code you want to add in Packalyst, which contains more than 5,500 packages.
Micro-service &; application program interface
Lumen is a performance-centric micro-framework based on Laravel. Using the high-performance API provided by Lumen, micro-projects can be developed more simply and quickly. Lumen integrates all the important features of Laravel with minimal configuration. You only need to copy the code into Laravel project to realize the complete transplantation of the framework.
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
$ app-& gt; get('/'),function() {
Return to view ("Lumens");
});
$ app-& gt; post('framework/{id} ',function($framework) {
$ this-& gt; Scheduling (new energy ($ framework));
});
HTTP routing
Laravel has a fast and efficient routing system similar to Ruby on Rails. It allows users to associate all parts of the application by entering a path in the browser.
Route::get('/'),function () {
Return "hello world";
});
HTTP middleware
Route::get('/'),function () {
Return "hello world";
});
Laravel can protect applications through middleware-middleware will process, analyze and filter HTTP requests that arrive at the server. You can use middleware to authenticate registered users and avoid cross-site scripting attacks (XSS) and other security issues.
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
Namespace App \ Http \ Middleware
Use closures;
Old middleware class {
Public function handle ($request, closure $ next) (
if($ request-& gt; Enter ('age') < = 200) {
Return redirection ("home");
}
Return $ next ($ request);
}
}
stash
Laravel provides a robust caching system, which can make applications load faster and bring better user experience.
Cache::extend('mongo', function ($app) {
Return Cache::repository (new MongoStore);
});
certificate
Safety is the most important thing. Laravel comes with local user authentication, so you can use the "Remember" option to remember users. In addition, you can also introduce some additional parameters, such as whether you are an active user or not.
if(Auth::attempt([' email ' = & gt; $email,' password' = & gt$password,' active' => 1], $ remember) {
//The user is remembered ...
}
Integrated fringe
Laravel Cashier can meet any needs in the process of developing payment system. In addition, it is synchronized and integrated into the user authentication system. Therefore, you no longer need to worry about how to integrate the billing system into the development.
$ User = User::find( 1);
$ user-& gt; Subscription ('monthly')-> create($ credit card token);
Task automation
Elixir is a Laravel API that allows us to define tasks using Gulp. We can use Elixir to define preprocessor to compress CSS and JavaScript.
Elixir (function (mixing) (
mix . browser ify(' main . js ');
});
encrypt
Secure applications should be able to encrypt data. In Laravel, you can use OpenSSL and AES-256-CBC encryption algorithms to meet all your encryption needs. In addition, all encrypted values are signed by an authentication code to prevent the encrypted information from being tampered with.
Use illuminate \ contracts \ encryption \ decrypt exception;
Try {
$ decrypted = Crypt::decrypt($ encrypted value);
} catch (DecryptException $e) {
//
}
event handling
It is very convenient to define, record and monitor events in Laravel applications. The listen property in the service provider EventServiceProvider contains a list of all events in the application.
Protected $listen = [
app \ Events \ podcast was purchased ' = & gt; [
Application \ Audience \ Email Purchase Confirmation',
],
];
Page marking
Pagination in Laravel is very simple, because it can generate a series of paging links according to the user's current page in the browser.
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
Namespace App \ Http \ Controllers
Use db;
Use app \ http \ controllers \ controller;
UserController class extension controller {
Common function index () {
$ users = DB::table(' users ')-& gt; Pagination (15);
Return to view ('user.index', ['users' = > $ users]);
}
}
Object relational mapping
Laravel contains a database processing layer, in which the object-relational mapping is called eloquence. In addition, this object-relational mapping is also applicable to PostgreSQL.
$users = User::where('votes ',' & gt), 100)->; Take (10)->; get();
foreach ($users as $user) {
var _ dump($ user-& gt; Name);
}
unit testing
The development of unit testing is a time-consuming task, but it ensures that our application can work normally without problems. Laravel uses PHPUnit for unit testing.
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
Use Illuminate \ Foundation \ Testing \ without middleware;
Use illuminate \ foundation \ testing \ database transactions;
Class sample Test extended test case {
Common function testBasicExample() {
$ this-& gt; Please visit ('/')-> See ('Laravel 5 ')-& gt;; don tsee(' Rails ');
}
}
To-Do List (Queue)
Laravel offers the option of using to-do lists to handle complex and lengthy processes in the background. Well, it's actually a queue, which allows us to handle certain processes asynchronously, without requiring users to wait for a long time when loading pages.
queue::push(new send email($ message));