-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move Documentation from ReadME to Docs
- Fix PHPDocs, and Code Style
- Loading branch information
1 parent
be1c5de
commit b46b3cc
Showing
11 changed files
with
232 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/.phpunit.cache | ||
/build/ | ||
/coverage.clover | ||
.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
### **Validating Unique and Exists Rule** | ||
|
||
You can use custom rules to validate unique and exists rules for translatable attributes. | ||
|
||
#### TranslatableUnique | ||
|
||
Ensure that the attribute value is unique by checking its absence in the database; if the value already exists, raise a validation exception. | ||
|
||
##### Option 1 | ||
|
||
```php | ||
use Astrotomic\Translatable\Validation\Rules\TranslatableUnique; | ||
... | ||
|
||
$person = new Person(['name' => 'john doe']); | ||
$person->save(); | ||
|
||
$data = [ | ||
'name' => 'john doe', | ||
'email' => 'john@example.com' | ||
]; | ||
$validator = Validator::make($data, [ | ||
'name' => ['required', new TranslatableUnique(Person::class, 'name')], | ||
]); | ||
|
||
``` | ||
|
||
##### Option 2 | ||
|
||
```php | ||
use Astrotomic\Translatable\Validation\Rules\TranslatableUnique; | ||
... | ||
|
||
$person = new Person(['name' => 'john doe']); | ||
$person->save(); | ||
|
||
$data = [ | ||
'name:en' => 'john doe', | ||
'email' => 'john@example.com' | ||
]; | ||
|
||
$validator = Validator::make($data, [ | ||
'name:en' => ['required', Rule::translatableUnique(Person::class, 'name:en')], | ||
]); | ||
|
||
``` | ||
|
||
##### Option 2 | ||
|
||
```php | ||
use Astrotomic\Translatable\Validation\Rules\TranslatableUnique; | ||
... | ||
|
||
$person = new Person(['name' => 'john doe']); | ||
$person->save(); | ||
|
||
$data = [ | ||
'name:en' => 'john doe', | ||
'email' => 'john@example.com' | ||
]; | ||
|
||
$validator = Validator::make($data, [ | ||
'name:en' => ['required', Rule::translatableUnique(Person::class, 'name:en')], | ||
]); | ||
|
||
``` | ||
|
||
|
||
#### TranslatableExists | ||
|
||
Verify if the attribute value exists by confirming its presence in the database; if the value does not exist, raise a validation exception. | ||
|
||
|
||
##### Option 1 | ||
```php | ||
use Astrotomic\Translatable\Validation\Rules\TranslatableExists; | ||
... | ||
|
||
$person = new Person(['name' => 'john doe']); | ||
$person->save(); | ||
|
||
$data = [ | ||
'name' => 'john doe', | ||
'email' => 'john@example.com' | ||
]; | ||
$validator = Validator::make($data, [ | ||
'name' => ['required', new TranslatableExists(Person::class, 'name')], | ||
]); | ||
``` | ||
|
||
##### Option 2 | ||
```php | ||
use Astrotomic\Translatable\Validation\Rules\TranslatableExists; | ||
... | ||
|
||
$person = new Person(['name' => 'john doe']); | ||
$person->save(); | ||
|
||
$data = [ | ||
'name:en' => 'john doe', | ||
'email' => 'john@example.com' | ||
]; | ||
|
||
$validator = Validator::make($data, [ | ||
'name:en' => ['required', Rule::translatableExists(Person::class, 'name:en')], | ||
]); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.