If we have a chunk of users and we want to update their `email_verified_at`
, we may write the next code:
use \App\Models\User;
User::get()->each(function ($user) {
$user->update(['email_verified_at' => now()]);
});
But, Laravel comes with an amazing feature called Higher Order Messages
which enables us to use some of its collection methods as if they are properties:
// \App\Http\Controllers\UserController.php
use \App\Models\User;
/**
* Update the `email_verified_at` column of all registered users.
*/
public function updateEmailVerifiedAtOfAllUsers(): void
{
User::get()->each->update(['email_verified_at' => now()]);
}
To deepen into this tip go ahead to Laravel docs.