- average,
- avg
- contains
- each
- every
- filter
- first
- flatMap
- groupBy
- keyBy
- map
- max
- min
- partition
- reject
- skipUntil
- skipWhile
- some
- sortBy
- sortByDesc
- sum
- takeUntil
- takeWhile
- and unique.
How to use Higher Order Messages in Laravel?
To use higher order messages in Laravel you can chain any of the above methods like the code below. Do note that the main purpose of higher-order messages is to call each of the methods within the collection and perform the actions specified.
<?php use App\Models\Post; $posts = Post::where('views', '>', 500)->get(); $posts->each->markAsSpecial();
<?php // within the Post model you can define the code below public function markAsSpecial() { $this->update(['special' => true]); }
<?php $users = User::query()->limit(100)->get(); // Higher Order Messages (very expressive) $users->each->markAsSpecial(); // Normal / Common way (slightly more to write) $users->each(function ($user) { $user->markAsSpecial(); });
Leave a reply