dwightwatson / validating

Automatically validating Eloquent models for Laravel
MIT License
968 stars 76 forks source link

Bypass validation on delete #81

Open chriscook opened 9 years ago

chriscook commented 9 years ago

Is there is a way to bypass all validation on deletion, without having to specify separate rule sets? Something similar to forceSave()?

dwightwatson commented 9 years ago

I like this idea, I'll take a look into it. Unfortunately forceDelete() is already taken by soft deleting though.

You can still achieve this though, something like:

$user->setValidating(false);
$user->delete();
chriscook commented 9 years ago

Ah, I hadn't spotted setValidating(). Thanks- that will help me a lot.

One idea could be to have an array property on the model to determine which operations to validate on;

protected $validateOn = [
    'create',
    'update'
];

For models without the property, all operations would trigger validation (same as it currently is).

It could even be beneficial to be able to specify rule sets for each operation:

protected $validateOn = [
    'create' => 'saving',
    'update' => 'updating'
];

(if they're not specified, use the default rule set).