Files
famous-ly4-ev/app-modules/booking/src/Exceptions/DriverAssignmentNotAllowedException.php
T

28 lines
717 B
PHP
Raw Normal View History

<?php
namespace Modules\Booking\Exceptions;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Modules\Booking\Models\Booking;
use RuntimeException;
class DriverAssignmentNotAllowedException extends RuntimeException
{
public static function notConfirmed(Booking $booking): self
{
return new self(
"Booking [{$booking->booking_ref}] cannot have a driver assigned because its status is [{$booking->status->value}], not confirmed."
);
}
public function render(Request $request): ?JsonResponse
{
if ($request->expectsJson()) {
return response()->json(['message' => $this->getMessage()], 422);
}
return null;
}
}