Home > Article > PHP Framework > Laravel’s new features: high-level messaging
Laravel The emergence of 5.4 framework will definitely also New features will appear as a result. One of these is support for higher-order messaging on collections. The so-called higher-order messaging (Higher Order Messaging) is actually a design pattern for querying and operating on collections of objects in a purely object-oriented manner.
The best way to demonstrate new features is through example code. Suppose you have a collection and want to operate on each element in it:
$invoices->each(function($invoice) { $invoice->pay(); });
With the new features you can The above code is simplified as follows:
$invoices->each->pay();
Another demonstration example is as follows:
$employees->reject(function($employee) { return $employee->retired; })->each(function($employee) { $employee->sendPayment(); });
Similarly, through the new features of 5.4 we can simplify it as follows:
$employees->reject->retired->each->sendPayment();
That’s it The entire content of the article, please pay attention to laravel framework introductory tutorial for more information!
Related recommendations:
Implementation of ACL user authorization and permission checking functions in Laravel 5.1 framework
Laravel 5.1 Framework How to create a custom Artisan console command
The above is the detailed content of Laravel’s new features: high-level messaging. For more information, please follow other related articles on the PHP Chinese website!