Higher Order Messages

Jan 05, 2024

If we have a chunk of users and we want to update their `email_verified_at` we may write:

 

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 were 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()]);
}

AI Assistant

Summarize, simplify, and ask questions about this content using your preferred AI provider.

Text Tools

Generate cleaner and easier-to-read versions of this content instantly

Have a Question?

Ask anything related to this content and get a focused AI-generated answer.

0/500
Mahmoud Ramadan
Author

Mahmoud Ramadan

Mahmoud is the creator of Digging Code and a contributor to Laravel since 2020.