Stop Eloquent model from saving

To preventing Laravel Eloquent models from being inserted into the database, you can attach a callback to the creating event on the model and return false

This will tell Eloquent not to insert the model into the database. Equally you can do the same for both the updating and deleting events.

There a multiple different event you can use but anything with ing (ie. saving, deleting) can be cancelled by returning False

See Laravel documentation; Events

<?php
use Illuminate\Database\Eloquent\Model;

class User extends Model {
    public static function booted() {
        static::creating(function($model)) {
            return false;
        }
    }

    ....
}

Leave a comment

Your email address will not be published. Required fields are marked *