Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

simao's avatar
Level 1

activate a member when a date arrives

Hi, I have a members table with 4 columns: First Name, Second Name, Activation_date and Status(default=0). I want to change the value of Status from 0 to 1 when the date in Activation_date column arrives. what is the best pattern to do that

Thanks.

0 likes
3 replies
Thyrosis's avatar

Is there a specific time that the user needs to get activated? Or is it just 'on that day'?

You could use the task scheduler for these kind of things. Just use the daily() frequency and the task will get executed every day at midnight.

From there, it is just a matter of finding all users with a activation date of today and status is 0 and update their status.

Find the task scheduling docs here: https://laravel.com/docs/5.5/scheduling

1 like
simao's avatar
Level 1

@Thyrosis I want that the activation (status = 1) be executed automatically when activation_date much today date.

Thyrosis's avatar

Then scheduling is your way forward. Something like this in the App\Console\Kernel file:

    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            // There is a much better way to do this, but my brain doesn't want to cooperate today
            foreach (App\User::where('status', 0)->where('activation_date', { today })->get() as $user) {
                $user->update(['status' => 1]);
            }
        })->daily();
    }
1 like

Please or to participate in this conversation.