%PDF- %PDF-
Direktori : /var/www/html/diaspora/api/app/Console/Commands/ |
Current File : /var/www/html/diaspora/api/app/Console/Commands/SendNotificationsForEventTheDayBefore.php |
<?php namespace App\Console\Commands; use App\Models\Device; use App\Models\Event; use App\Notifications\NotifyUsersForEventComingUp; use Carbon\Carbon; use Illuminate\Console\Command; class SendNotificationsForEventTheDayBefore extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'command:sendNotificationsForEventTheDayBefore'; /** * The console command description. * * @var string */ protected $description = 'Send scheduled notifications for events'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. */ public function handle() { $start = Carbon::now() ->addHours(24); $end = Carbon::now() ->addHours(25); $events = Event::query() ->where('status', Event::PUBLISHED) ->where('when', '>=', $start) ->where('when', '<', $end) ->get(); /** @var Event $event */ foreach ($events as $event) { $event->devices->each(function (Device $device) use ($event) { $event->createNotification($device, 'EVENT_REMINDER'); $device->notify(new NotifyUsersForEventComingUp($event, $device->user->getBadge())); }); } } }