Is there a value in config('app.timezone')?
Apr 15, 2022
14
Level 17
Laravel Scheduler DateTime error
I create that schedule in Kernel
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->call(function () {
Notification::create([
'message' => sprintf('Item '),
'model_type' => 'item',
'model_id' => 4000,
'user_id' => 5000,
]);
$deadItemsDays = Setting::where('name', 'period_for_any_items_notification')->first()->value;
$deadNewItems = Setting::where('name', 'period_for_new_items_notification')->first()->value;
dd($deadItemsDays);
$items = Item::query()
->where('closed', false)
->where('suspended', false)
->where('on_hold', false)
->whereHas('actions', function ($query) {
$query->whereDate('created_at', '<=', now()->subDays($this->getDeadItemsDays())->startOfDay());
})
->get();
$technicians = User::role('technician')->get();
foreach ($items as $item) {
foreach ($technicians as $technician) {
Notification::create([
'message' => sprintf('Item %has no actions for %d', $item->id, $deadNewItems),
'model_type' => 'item',
'model_id' => $item->id,
'user_id' => $technician->id,
]);
}
}
$new_items = Item::query()
->where('new', true)
->whereHas('actions', function ($query) {
$query->whereDate('created_at', '<=', now()->subDays($this->getDeadNewItemsDays())->startOfDay());
})
->get();
$technicians = User::role('technician')->get();
foreach ($new_items as $item) {
foreach ($technicians as $technician) {
Notification::create([
'message' => sprintf('Item %has no actions for %d', $item->id, $deadItemsDays),
'model_type' => 'item',
'model_id' => $item->id,
'user_id' => $technician->id,
]);
}
}
})->everyMinute();
}
when commanding php artisan schedule:list
I have an err :
TypeError
DateTime::setTimezone(): Argument #1 ($timezone) must be of type DateTimeZone, null given
at vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleListCommand.php:42
38▕ $event->expression,
39▕ $event->description,
40▕ (new CronExpression($event->expression))
41▕ ->getNextRunDate(Carbon::now()->setTimezone($event->timezone))
➜ 42▕ ->setTimezone($this->option('timezone', config('app.timezone')))
43▕ ->format('Y-m-d H:i:s P'),
44▕ ];
45▕ }
46▕
+14 vendor frames
15 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
HOW COULD I TEST THAT ? HOW to run it ?
Please or to participate in this conversation.