Skip to content

Latest commit

 

History

History
14 lines (11 loc) · 364 Bytes

call-each-as-property.md

File metadata and controls

14 lines (11 loc) · 364 Bytes

Call "each" as a property instead of a method

If you're looping through a collection and performing a simple operation, you can call "each" as a property instead of a method.

$posts = Post::all();

// This is shorter version
$posts->each->update(['active' => 1]);

// ..of this
$posts->each(function ($post) {
    $post->update(['active' => 1]);
});