Skip to content

Feature/unique with trashed #6661

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

Closed
wants to merge 4 commits into from

Conversation

yaminlam
Copy link

No description provided.

@yaminlam
Copy link
Author

The built-in unique rule does not automatically ignore soft-deleted records. This means if a record exists with a non-null deleted_at, the default unique validation would still fail.

My UniqueWithTrashed rule automatically ignores soft-deleted items, making it easier to enforce uniqueness only among active records without repeating custom query logic each time. It’s especially helpful in applications that heavily use soft deletes.

@yaminlam
Copy link
Author

The UniqueWithTrashed rule is helpful because it ignores soft-deleted items (deleted_at not null) when checking uniqueness. This ensures that only active records are considered, which the default unique rule doesn’t do automatically.

@taylorotwell
Copy link
Member

Rule::unique()->withoutTrashed()

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.

2 participants