Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add a new function onlyTrashed #44989

Merged
merged 3 commits into from Nov 17, 2022

Conversation

michaelnabil230
Copy link
Contributor

@michaelnabil230 michaelnabil230 commented Nov 17, 2022

This PR introduces an "onlyTrashed" validation rule in Exists and Unique.

For example, we want a user to be able to create a new row in the database user, but we want to search in the database where the deleted_at is not null.
And the same since the same function is in the same trait SoftDeletes

Usage:

Validator::make(
    [
        'name' => 'Michael Nabil',
    ],
    [
        'name' => [
            'required', 
            Rule::exists('users')->where('id', $this->id)->onlyTrashed(),  
            Rule::unique('users')->where('id', $this->id)->onlyTrashed(),  // Or
        ],
    ]
);

@taylorotwell taylorotwell merged commit 25c8fed into laravel:9.x Nov 17, 2022
@michaelnabil230 michaelnabil230 deleted the DatabaseRule branch November 17, 2022 14:31
@martinbean
Copy link
Contributor

The naming seems off on this for me. “Only trashed” reads to me as if it’ll only check soft-deleted records; not omit soft-deleted (trashed) records when doing the exists/unique checking 😕

@s4muel
Copy link
Contributor

s4muel commented Nov 27, 2022

The naming seems off on this for me. “Only trashed” reads to me as if it’ll only check soft-deleted records; not omit soft-deleted (trashed) records when doing the exists/unique checking 😕

@martinbean Well, it reads to you just fine, because it really checks only within soft-deleted items 🤯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants