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

Laravel’s new features: high-level messaging

不言
不言Original
2018-07-31 13:46:222609browse

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!

Statement:
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