Skip to content

Commit

Permalink
Docs updated to be synced with online documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeping-owl committed Oct 20, 2014
1 parent 1dfe0fb commit 5bca6c3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/docs/01_Getting_Started/00_Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@

```bash
$ php artisan admin:install
```
```
5. All done! Now go to the `<your_site_url>/admin` and use default credentials `admin` / `SleepingOwl`.
33 changes: 25 additions & 8 deletions src/docs/01_Getting_Started/05_Validation.md
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` &ndash; check if field is valid url stub (without slashes)
- `url_stub_full` &ndash; check if field is valid url stub (with slashes)
- `required_only_on_create` &ndash; 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` &ndash; 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` &ndash; check if field is valid url stub (without slashes)
- `url_stub_full` &ndash; check if field is valid url stub (with slashes)
2 changes: 2 additions & 0 deletions src/docs/06_Columns/07_date.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/docs/07_Form_Elements/00_Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/docs/07_Form_Elements/05_date.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/docs/07_Form_Elements/06_time.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/docs/07_Form_Elements/07_timestamp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/docs/07_Form_Elements/11_multiSelect.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function setCategoriesAttribute($categories)
{
$this->categories()->detach();
if ( ! $categories) return;
if ( ! $this->exists) $this->save();

$this->categories()->attach($categories);
}
Expand Down

0 comments on commit 5bca6c3

Please sign in to comment.