Commands are not something that users typically run. Change that to a job or something like that.
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.
Please or to participate in this conversation.