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

[5.x] Update string based validation rules #1298

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions content/collections/docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ You may use any validation rule provided by Laravel. You can view the complete l
handle: highlander
field:
type: text
validate: 'unique_entry_value:{collection},{id},{site}'
validate: 'new \Statamic\Rules\UniqueEntryValue({collection}, {id}, {site})'
```

This works like Laravel's `unique` validation rule, but for Statamic entries. The rule should be used verbatim as shown above. Statamic will replace the `collection`, `id`, and `site` behind the scenes.
Expand All @@ -120,10 +120,10 @@ You can then customize the error message right in your `resources/lang/{lang}/va
handle: foo
field:
type: text
validate: 'unique_term_value:{taxonomy},{id},{site}'
validate: 'new \Statamic\Rules\UniqueTermValue({taxonomy}, {id}, {site})'
```

This works like the `unique_entry_value` rule, but for taxonomy terms.
This works like the `UniqueEntryValue` rule, but for taxonomy terms.

### Unique User Value

Expand All @@ -132,13 +132,13 @@ This works like the `unique_entry_value` rule, but for taxonomy terms.
handle: login
field:
type: text
validate: 'unique_user_value:{id}'
validate: 'new \Statamic\Rules\UniqueUserValue({id})'
```

This works like the `unique_entry_value` rule, but for users.
This works like the `UniqueEntryValue` rule, but for users.

:::tip
If you want to override the field that is being validated (e.g. in Livewire Form Objects), you can do so by passing a second parameter to the validation rule, such as `unique_user_value:{id},username`.
If you want to override the field that is being validated (e.g. in Livewire Form Objects), you can do so by passing a second parameter to the validation rule, such as `new \Statamic\Rules\UniqueUserValue({id}, "username")`.
:::

## Custom Rules
Expand Down