How to avoid create record in laravel model creating event

Viewed 248

I'm currently using Laravel 8 and I want check a field when my model 'creating' event fired. If my field isn't null, I want cancel creating record. my event is like below:

protected static function booted(){
    static::creating(function ($contactMessage){
        if(request('birthday') != null)
            //Here I want Stop creating record but don't know how!!!
    });
}

1 Answers

Return false if you want to stop the creation of the record. Model@performInsert will check to see if a false was returned from any event listener for the creating event.

Related