You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks to the interesting Rule class (Illuminate\Validation\Rule) laravel's form requests are much more readable and more nice to look at. however, there's a little thing that's been annoying me through development.
we do have unique and exists methods in the Rule class which are used more often. there's also a withoutTrashed method which comes in handy when we are using the SoftDeletes trait in the models.
I've checked the code and realized we can also pass a model as the first argument to the unique method..
if that's the case then while initializing it, we can also check if the model is using soft deletes and apply withoutTrashed automatically.
I think some simple checks as below would provide the functionality in question:
if (is_subclass_of($table, Model::class)) {
$model = new $table;
if (! $model->forceDeleting) {
$this->withoutTrashed();
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Greetings everyone
Thanks to the interesting
Rule
class (Illuminate\Validation\Rule) laravel's form requests are much more readable and more nice to look at. however, there's a little thing that's been annoying me through development.we do have
unique
andexists
methods in theRule
class which are used more often. there's also awithoutTrashed
method which comes in handy when we are using theSoftDeletes
trait in the models.I've checked the code and realized we can also pass a model as the first argument to the
unique
method..if that's the case then while initializing it, we can also check if the model is using soft deletes and apply
withoutTrashed
automatically.I think some simple checks as below would provide the functionality in question:
I'm wondering what you think about it
Regards, Ali.
Beta Was this translation helpful? Give feedback.
All reactions