-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs updated to be synced with online documentation
- Loading branch information
1 parent
1dfe0fb
commit 5bca6c3
Showing
8 changed files
with
45 additions
and
9 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
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 |
---|---|---|
@@ -1,13 +1,30 @@ | ||
The easiest way to perform validation in you models is to extend `SleepingOwl\Models\SleepingOwlModel`. You must implement `getValidationRules()` method in your model, that must return validation rules, and thats all. | ||
There is two easy ways to perform validation in your models, you can combine them if you want. And there is one hard way. First of all you must extend your models from `SleepingOwl\Models\SleepingOwlModel`. | ||
|
||
The other way is to implement `SleepingOwl\Models\Interfaces\ValidationModelInterface` interface. It declares 2 methods: `validate($data)` and `getValidationRules()`. You must manually write validation there. If validation fails method must throw `SleepingOwl\Admin\Exceptions\ValidationException`. | ||
## Easy Ways | ||
|
||
### New Validation Rules | ||
### 1. In Form Elements | ||
|
||
- `url_stub` – check if field is valid url stub (without slashes) | ||
- `url_stub_full` – check if field is valid url stub (with slashes) | ||
- `required_only_on_create` – field required only on new entity creation, usefull for image field | ||
You can add validation rules to your form elements: | ||
|
||
```php | ||
FormItem::text('title')->required()->unique()->validationRule('my-custom-rule') | ||
``` | ||
|
||
`required()` accepts one parameter: `true` if required only on create, `false` if always required. No parameter equals `false`. | ||
|
||
Use `unique()` to set this field to be unique in this model. | ||
|
||
You can use `validationRule($rule)` to add any rule you want. You can use pipe delimiter `|`. | ||
|
||
### Updated Validation Rules | ||
### 2. In Your Model | ||
|
||
- `unique` – same as laravel 'unique', but automatically exclude current entity from search. *(works only if your model extends `SleepingOwlModel`)* | ||
You can implement `public function getValidationRules()` method in your model, that must return validation rules, and thats all. | ||
|
||
## Hard Way | ||
|
||
The other way is to implement `SleepingOwl\Models\Interfaces\ValidationModelInterface` interface. It declares 2 methods: `validate($data)` and `getValidationRules()`. You must manually write validation there. If validation fails method must throw `SleepingOwl\Admin\Exceptions\ValidationException`. | ||
|
||
## New Validation Rules | ||
|
||
- `url_stub` – check if field is valid url stub (without slashes) | ||
- `url_stub_full` – check if field is valid url stub (with slashes) |
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
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