Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anilaeus's avatar

Model static::creating canceling not work properly

I am using Laravel, Livewire, FilamentPHP.

In my model i have

protected static function boot(): void
    {
        parent::boot();
        static::creating(function ($model) {
            $uuid = Uuid::uuid4();

            $reservation = Reservation::where('reservation_date', now()->format("Y-m-d"))->where('user_id', $model->user_id)->first();
            if (!$reservation?->id) {
                Notification::make()->title("This user doesn't have a reservation.")->danger()->send();
                return false;
            }
            $model->reservation_id = $reservation->id;
            return false;

            $model->order_uuid = $uuid->toString();
        });
    }

and then when i change my code block to ->

protected static function boot(): void
    {
        parent::boot();
        static::creating(function ($model) {
            $uuid = Uuid::uuid4();

            $reservation = Reservation::where('reservation_date', now()->format("Y-m-d"))->where('user_id', $model->user_id)->first();
            if (!$reservation?->id) {
                Notification::make()->title("This user doesn't have a reservation.")->danger()->send();
                return false;
            } else {
                $model->reservation_id = $reservation->id;
                $model->order_uuid = $uuid->toString();
            }

        });
    }

then this time it throw me-> Missing required parameter for [Route: filament.admin.resources.orders.edit] [URI: admin/orders/{record}/edit] [Missing parameter: record]. error.

I expect whenever there is no $reservation->id it will send a notification and it will stop saving it. However in the reality it returns me:

  • 404 Not Found Page ('I wish it was just sending the notificaiton what i want instead of returning this page')

  • After refreshing the page manually it show 2 notification -> Model Created Notification & This user doesn't have a reservation Notification.

what i am doing wrong here? Can anybody help me?

0 likes
0 replies

Please or to participate in this conversation.