Skip to content

Commit 137331f

Browse files
Docs: Add documentation for unique()->withoutTrashed() method (#10163)
* docs: 📝 Add documentation for `unique()->withoutTrashed()` Explains how to use `withoutTrashed()` in `Rule::unique()` to exclude soft-deleted records from uniqueness checks. - Clarifies default behavior of `unique()` rule (includes soft-deletes). - Shows basic usage and customization of `$deletedAtColumn`. * Update validation.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 8f17d61 commit 137331f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

validation.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,16 @@ You may specify additional query conditions by customizing the query using the `
20212021

20222022
'email' => Rule::unique('users')->where(fn (Builder $query) => $query->where('account_id', 1))
20232023

2024+
**Ignoring Soft Deleteded Records in Unique Checks:**
2025+
2026+
By default, the unique rule includes soft deleted records when determining uniqueness. To exclude soft deleted records from the uniqueness check, you may invoke the `withoutTrashed` method:
2027+
2028+
Rule::unique('users')->withoutTrashed();
2029+
2030+
If your model uses a column name other than `deleted_at` for soft deleted records, you may provide the column name when invoking the `withoutTrashed` method:
2031+
2032+
Rule::unique('users')->withoutTrashed('was_deleted_at');
2033+
20242034
<a name="rule-uppercase"></a>
20252035
#### uppercase
20262036

0 commit comments

Comments
 (0)