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

r10maro90's avatar

How to pass variables to Laravel command and Kernel

How to pass variables to Laravel command and Kernel

I have a command that runs every 2 weeks on a chosen day(selected by the user).

I would like to pass the $choosenday value to the command then into the kernel. I'm still new to laravel so trying to figure out the flow.

I know that I should add the argument to the command like this:

protected $signature = 'safetyreminder:every2weeks {chosenday}';

and then in the handle add:

$chosenday = $this->argument('chosenday');

But I'm stuck here. Each chosen day is different for each user and have been pulled from the database during the foreach loop.

Here what I have so far:

class EmployeeSafetyReminderEvery2Weeks extends Command {

protected $signature = 'safetyreminder:every2weeks {chosenday}';

protected $description = 'This remind employees every 2 weeks';




public function __construct()
{
    parent::__construct();
} 



public function handle()
{


    $chosenday = $this->argument('chosenday');
    
    $safetyReminders = SafetyReminder::with('reminder', 'team', 'manager', 'day')
                                        ->get(); 


    foreach($safetyReminders as $safetyReminder){


        $frequencyId = $safetyReminder->reminder->frequency_id;  

        if($frequencyId == 2){


            $teamId = $safetyReminder->team_id;
            $reminder = $safetyReminder->reminder;
            $teamManager = $safetyReminder->manager;
            $chosenday = $safetyReminder->day->name;  // Day the user wants the reminder to go out

            $employees = User::where('team_id', $teamId)->get();

        
            foreach($employees as $employee){

                $user = $employee;

                // send Email job
                dispatch(new EmployeeSafetyReminderEmailJob($user, $reminder, $teamManager));   


            }


        }


    }
     

}

}

Any help or suggestion would be appreciated.

0 likes
3 replies
bugsysha's avatar

Commands are not something that users typically run. Change that to a job or something like that.

r10maro90's avatar

'Commands are not something that users typically run' does this mean its wrong trying to do it this way? That's what I'm not sure about. I'm not sure how a job would be used in this scenario.

Please or to participate in this conversation.