%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Console/Commands/
Upload File :
Create Path :
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Console/Commands/BookingReminders.php

<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use App\Models\Booking;
use Illuminate\Console\Command;
use App\Notifications\BookingReminder;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send booking reminders 2 hours before';

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $bookings = Booking::orderBy('start_date', 'desc')
            ->where('start_date', '<=', Carbon::now()->addHour(48))
            ->where('start_date', '>=', Carbon::now())
            ->where('is_reminder_sent', false)
            ->notCancelled()
            ->get();

        foreach($bookings as $booking) {
            $booking->user->notify(new BookingReminder($booking));
            $booking->is_reminder_sent = true;
            $booking->save();
        }
    }
}

Zerion Mini Shell 1.0