Home > PHP Framework > Laravel > Laravel's new features: high-level messaging

Laravel's new features: high-level messaging

不言
Release: 2018-07-31 13:46:22
Original
2653 people have browsed it

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(); 
});
Copy after login

With the new features you can The above code is simplified as follows:

$invoices->each->pay();
Copy after login

Another demonstration example is as follows:

$employees->reject(function($employee) { 
    return $employee->retired; 
})->each(function($employee) { 
    $employee->sendPayment(); 
});
Copy after login

Similarly, through the new features of 5.4 we can simplify it as follows:

$employees->reject->retired->each->sendPayment();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template