Skip to content

Commit

Permalink
Added validation rules for a slug field
Browse files Browse the repository at this point in the history
  • Loading branch information
m2de authored Sep 22, 2018
2 parents f077e4d + 3ee6b29 commit b39a9e4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src-php/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public function fields(Request $request)
{
return [
ID::make()->sortable(),

TextWithSlug::make(__('Name'), 'name')->sortable()->slug(__('Slug')),
Slug::make(__('Slug'), 'slug')->sortable(),
Slug::make(__('Slug'), 'slug')->rules('required', 'unique:roles')->sortable(),

Checkboxes::make(__('Permissions'), 'permissions')->options(collect(Policy::all())->mapWithKeys(function ($policy) {
return [
Expand Down

1 comment on commit b39a9e4

@bonzai
Copy link
Contributor

@bonzai bonzai commented on b39a9e4 Sep 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should split validation rules into creation and update because right now it's impossible to update the role:

Slug::make(__('Slug'), 'slug')
    ->creationRules('required', 'unique:roles')
    ->updateRules('required', 'unique:roles,slug,{{resourceId}}')
    ->sortable(),

Please sign in to comment.