Skip to content

Commit

Permalink
validation rules
Browse files Browse the repository at this point in the history
  • Loading branch information
vyuldashev committed Aug 27, 2018
1 parent 8f27d1f commit 60fbea1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vyuldashev\NovaPermission;

use Illuminate\Validation\Rule;
use Laravel\Nova\Resource;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -68,9 +69,14 @@ public function fields(Request $request)
return [
ID::make()->sortable(),

Text::make(__('nova-permission-tool::permissions.name'), 'name'),
Text::make(__('nova-permission-tool::permissions.name'), 'name')
->rules(['required', 'string', 'max:255'])
->creationRules('unique:' . config('permission.table_names.permissions'))
->updateRules('unique:' . config('permission.table_names.permissions') . ',name,{{resourceId}}'),

Select::make(__('nova-permission-tool::permissions.guard_name'), 'guard_name')->options($guardOptions->toArray()),
Select::make(__('nova-permission-tool::permissions.guard_name'), 'guard_name')
->options($guardOptions->toArray())
->rules(['required', Rule::in($guardOptions)]),

DateTime::make(__('nova-permission-tool::permissions.created_at'), 'created_at')->exceptOnForms(),
DateTime::make(__('nova-permission-tool::permissions.updated_at'), 'updated_at')->exceptOnForms(),
Expand All @@ -82,7 +88,7 @@ public function fields(Request $request)
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
* @return array
*/
public function cards(Request $request)
Expand All @@ -93,7 +99,7 @@ public function cards(Request $request)
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
* @return array
*/
public function filters(Request $request)
Expand All @@ -104,7 +110,7 @@ public function filters(Request $request)
/**
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
* @return array
*/
public function lenses(Request $request)
Expand All @@ -115,7 +121,7 @@ public function lenses(Request $request)
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
* @return array
*/
public function actions(Request $request)
Expand Down
10 changes: 8 additions & 2 deletions src/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vyuldashev\NovaPermission;

use Illuminate\Validation\Rule;
use Laravel\Nova\Resource;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -68,9 +69,14 @@ public function fields(Request $request)
return [
ID::make()->sortable(),

Text::make(__('nova-permission-tool::roles.name'), 'name'),
Text::make(__('nova-permission-tool::roles.name'), 'name')
->rules(['required', 'string', 'max:255'])
->creationRules('unique:' . config('permission.table_names.roles'))
->updateRules('unique:' . config('permission.table_names.roles') . ',name,{{resourceId}}'),

Select::make(__('nova-permission-tool::roles.guard_name'), 'guard_name')->options($guardOptions->toArray()),
Select::make(__('nova-permission-tool::roles.guard_name'), 'guard_name')
->options($guardOptions->toArray())
->rules(['required', Rule::in($guardOptions)]),

DateTime::make(__('nova-permission-tool::roles.created_at'), 'created_at')->exceptOnForms(),
DateTime::make(__('nova-permission-tool::roles.updated_at'), 'updated_at')->exceptOnForms(),
Expand Down

0 comments on commit 60fbea1

Please sign in to comment.