%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Http/Controllers/Booking/
Upload File :
Create Path :
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Http/Controllers/Booking/ReschedulingController.php

<?php

namespace App\Http\Controllers\Booking;

use Carbon\Carbon;
use App\Models\Booking;
use App\Notifications\Client\BookingRescheduled;
use App\Notifications\Therapist\BookingRescheduled as TherapistBookingRescheduled;
use Illuminate\Http\Request;
use App\Http\Requests\UpdateBooking;
use App\Http\Controllers\Controller;
use App\Http\Resources\BookingResource;

class ReschedulingController extends Controller
{
    /**
     * Get the booking for rescheduling
     * 
     * @param int $id
     * @param Request $request
     */
    public function show($id, Request $request)
    {
        $booking = Booking::where('id', $id)
            ->with('user', 'payment', 'therapist')
            ->firstOrFail();

        $this->authorize('view', $booking);

        return response()->json($booking);
    }

    /**
     * Update the bookings time and date
     * 
     * @param int $id
     * @param UpdateBooking $request
     */
    public function update($id, UpdateBooking $request)
    {
        $booking = Booking::where('id', $id)->notCancelled()->firstOrFail();

        $this->authorize('update', $booking);

        $booking->start_date = Carbon::parse($request->get('slot'));
        $booking->end_date = Carbon::parse($request->get('slot'))->addHour();
        $booking->save();

        $booking->user->notify(new BookingRescheduled($booking));
        $booking->therapist->user->notify(new TherapistBookingRescheduled($booking));

        return new BookingResource($booking);
    }
}

Zerion Mini Shell 1.0