Laravel is a young framework with a bright future. Its community is full of vitality, the relevant documentation and tutorials are complete and clear, and it provides the necessary functions for developing modern applications quickly and safely. In statistics on the popularity of PHP frameworks in recent years, Laravel has always been far ahead. So why is laravel framework popular?
Features of Laravel:
Modularity and Extensibility
Laravel focuses on code modularity and scalability. You can find any file you want to add in the Packalyst directory, which contains over 5500 packages. The goal of Laravel is to enable you to find any file you want.
Microservices and program interfaces
Lumen is a micro-framework derived from laravel that focuses on streamlining. Its high-performance programming interface allows you to develop micro-projects more easily and quickly. Lumen integrates all the important features of laravel with minimal configuration. You can migrate the complete framework by copying the code to the laravel project.
<?php $app->get('/', function() { return view('lumen'); }); $app->post('framework/{id}', function($framework) { $this->dispatch(new Energy($framework)); });
HTTP path
Laravel has a fast and efficient routing system similar to Ruby on Rails. It allows users to relate parts of an application by typing paths into the browser.
HTTP Middleware
Route::get('/', function () { return 'Hello World'; });
Applications can be protected by middleware - middleware handles the analysis and filtering of HTTP requests on the server. You can install middleware to authenticate registered users and avoid issues like cross-site scripting (XSS) or other security conditions.
<?php namespace App/Http/Middleware; use Closure; class OldMiddleware { public function handle($request, Closure $next) { if ($request->input('age') <= 200) { return redirect('home'); } return $next($request); } }
Caching
Your application gets a robust caching system that can be tuned to make the application load faster, which can give Provide your users with the best experience.
Cache::extend('mongo', function($app) { return Cache::repository(new MongoStore); });
Authentication
Security is critical. Laravel comes with local user authentication and can use the "remember" option to remember users. It also allows you to set some additional parameters, such as showing whether the user is active.
if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1 ], $remember)) { // The user is being remembered... }
Various integrations
Laravel Cashier can meet all the needs you need to develop a payment system. In addition to this, it synchronizes and integrates user authentication systems. So, you no longer need to worry about integrating your billing system into your development.
$user = User::find(1); $user->subscription('monthly')->create($creditCardToken);
Task Automation
Elixir is a Laravel programming interface that allows us to use Gulp to define tasks. We can use Elixir to define preprocessors that can streamline CSS and JavaScript. .
elixir(function(mix) { mix.browserify('main.js'); });
Encryption
A secure application should be able to encrypt data. Using Laravel, you can enable the OpenSSL security encryption algorithm AES-256-CBC to meet all your needs. In addition, all encrypted values are signed by a verification code that detects whether the encrypted information has been changed.
use Illuminate/Contracts/Encryption/DecryptException; try { $decrypted = Crypt::decrypt($encryptedValue); } catch (DecryptException $e) { // }
Event handling
Events in your application are defined, logged and listened to very quickly. The listen in the EventServiceProvider event contains a list of all events logged on your application.
protected $listen = [ 'App/Events/PodcastWasPurchased' => [ 'App/Listeners/EmailPurchaseConfirmation', ], ];
Paging
Paging in Laravel is very easy because of its ability to generate a series of links based on the current page of the user's browser.
<?php namespace App/Http/Controllers; use DB; use App/Http/Controllers/Controller; class UserController extends Controller { public function index() { $users = DB::table('users')->paginate(15); return view('user.index', ['users' => $users]); } }
Object Relational Mapping (ORM)
Laravel contains a layer that handles databases, and its object-relational mapping is called Eloquent. In addition, this also applies to PostgreSQL.
$users = User::where('votes', '>', 100)->take(10)->get(); foreach ($users as $user) { var_dump($user->name); }
Unit testing
The development of unit tests is a time-consuming task, but it is the key to ensuring that our applications keep working properly. PHPUnit can be used to perform unit testing in Laravel.
<php use Illuminate/Foundation/Testing/WithoutMiddleware; use Illuminate/Foundation/Testing/DatabaseTransactions; class ExampleTest extends TestCase { public function testBasicExample() { $this->visit('/')->see('Laravel 5')->dontSee('Rails'); } }
The above is the detailed content of Why is laravel framework popular?. For more information, please follow other related articles on the PHP Chinese website!