From 5bca6c391c4bb2e33670b02ca2c6b0eab6a56010 Mon Sep 17 00:00:00 2001 From: Sleeping Owl Date: Mon, 20 Oct 2014 14:27:03 +0400 Subject: [PATCH] Docs updated to be synced with online documentation --- .../01_Getting_Started/00_Installation.md | 3 +- src/docs/01_Getting_Started/05_Validation.md | 33 ++++++++++++++----- src/docs/06_Columns/07_date.md | 2 ++ src/docs/07_Form_Elements/00_Overview.md | 8 +++++ src/docs/07_Form_Elements/05_date.md | 3 ++ src/docs/07_Form_Elements/06_time.md | 2 ++ src/docs/07_Form_Elements/07_timestamp.md | 2 ++ src/docs/07_Form_Elements/11_multiSelect.md | 1 + 8 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/docs/01_Getting_Started/00_Installation.md b/src/docs/01_Getting_Started/00_Installation.md index 830780ce..535d5af8 100644 --- a/src/docs/01_Getting_Started/00_Installation.md +++ b/src/docs/01_Getting_Started/00_Installation.md @@ -21,4 +21,5 @@ ```bash $ php artisan admin:install - ``` \ No newline at end of file + ``` + 5. All done! Now go to the `/admin` and use default credentials `admin` / `SleepingOwl`. \ No newline at end of file diff --git a/src/docs/01_Getting_Started/05_Validation.md b/src/docs/01_Getting_Started/05_Validation.md index 7b57c31b..5a4c4cda 100644 --- a/src/docs/01_Getting_Started/05_Validation.md +++ b/src/docs/01_Getting_Started/05_Validation.md @@ -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) \ No newline at end of file diff --git a/src/docs/06_Columns/07_date.md b/src/docs/06_Columns/07_date.md index 3dc1901b..ca9d792b 100644 --- a/src/docs/06_Columns/07_date.md +++ b/src/docs/06_Columns/07_date.md @@ -4,6 +4,8 @@ Cell content will be date or time value. Column::date('{field}') ``` +**Important**: you must have [intl](http://php.net/manual/en/book.intl.php) php extension installed to use this column. + ### Format Date and Time ```php diff --git a/src/docs/07_Form_Elements/00_Overview.md b/src/docs/07_Form_Elements/00_Overview.md index c2189b93..68b27757 100644 --- a/src/docs/07_Form_Elements/00_Overview.md +++ b/src/docs/07_Form_Elements/00_Overview.md @@ -19,6 +19,14 @@ Creates new form element and adds it to the current model configuration. - [textarea](textarea.html) - [ckeditor](ckeditor.html) - [view](view.html) + +### Validation + +```php +FormItem::text('title')->required()->unique()->validationRule('my-custom-rule') +``` + +See [details](../Getting_Started/Validation.html) about validation. ### Register Custom Type diff --git a/src/docs/07_Form_Elements/05_date.md b/src/docs/07_Form_Elements/05_date.md index 25ac9c34..a13192a9 100644 --- a/src/docs/07_Form_Elements/05_date.md +++ b/src/docs/07_Form_Elements/05_date.md @@ -4,6 +4,9 @@ Creates date input. FormItem::date('date', 'Date') ``` +**Important**: you must have [intl](http://php.net/manual/en/book.intl.php) php extension installed to use this form element. + + ![](/img/date.png) ### Opened State diff --git a/src/docs/07_Form_Elements/06_time.md b/src/docs/07_Form_Elements/06_time.md index f34f8e0d..0e2deda2 100644 --- a/src/docs/07_Form_Elements/06_time.md +++ b/src/docs/07_Form_Elements/06_time.md @@ -4,6 +4,8 @@ Creates time input. FormItem::time('time', 'Time') ``` +**Important**: you must have [intl](http://php.net/manual/en/book.intl.php) php extension installed to use this form element. + ![](/img/time.png) ### Opened State diff --git a/src/docs/07_Form_Elements/07_timestamp.md b/src/docs/07_Form_Elements/07_timestamp.md index 4cfd2c17..fe12c9c8 100644 --- a/src/docs/07_Form_Elements/07_timestamp.md +++ b/src/docs/07_Form_Elements/07_timestamp.md @@ -4,6 +4,8 @@ Creates time input. FormItem::timestamp('timestamp', 'DateTime') ``` +**Important**: you must have [intl](http://php.net/manual/en/book.intl.php) php extension installed to use this form element. + ![](/img/timestamp.png) ### Opened State diff --git a/src/docs/07_Form_Elements/11_multiSelect.md b/src/docs/07_Form_Elements/11_multiSelect.md index 7c62db31..e96ac46e 100644 --- a/src/docs/07_Form_Elements/11_multiSelect.md +++ b/src/docs/07_Form_Elements/11_multiSelect.md @@ -43,6 +43,7 @@ public function setCategoriesAttribute($categories) { $this->categories()->detach(); if ( ! $categories) return; + if ( ! $this->exists) $this->save(); $this->categories()->attach($categories); }