How to prevent a model from saving using Laravel events
1
In the boot()
method of your plugin, add this snippet:
Event::listen('eloquent.saving: System\Models\RequestLog', function ($model) {
if (str_ends_with($model->url, '/bad-url')) {
return false;
}
});
or the preferred method:
System\Models\RequestLog::saving(function ($model) {
if (str_ends_with($model->url, '/bad-url')) {
return false;
}
});
There are no comments yet
Be the first one to comment