Skip to content

Commit

Permalink
Update SettingGroupResource.php.stub
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvenga authored Feb 3, 2023
1 parent 5b19a05 commit 735e323
Showing 1 changed file with 7 additions and 32 deletions.
39 changes: 7 additions & 32 deletions stubs/MoonShine/Resources/SettingGroupResource.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,47 @@ namespace App\MoonShine\Resources;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Validation\Rule;
use Leeto\MoonShine\Fields\BelongsTo;
use Leeto\MoonShine\Fields\Date;
use Leeto\MoonShine\Fields\Text;
use Leeto\MoonShine\Filters\BelongsToFilter;
use Leeto\MoonShine\Resources\Resource;
use Leeto\MoonShine\Fields\ID;
use Leeto\MoonShine\Actions\FiltersAction;
use VI\LaravelSiteSettings\Models\Setting;
use VI\LaravelSiteSettings\Models\SettingGroup;

class SettingGroupResource extends Resource
{
public static string $model = Setting::class;
public static string $model = SettingGroup::class;

public static string $title = 'Settings';
public static string $title = 'Settings groups';

public string $titleField = 'slug';

public function fields(): array
{
return [
ID::make()->sortable(),
BelongsTo::make(
'Group',
'settingGroup',
new SettingGroupResource()
)->nullable()->sortable(),
Text::make('Slug', 'slug')->required()->sortable()->hint('a-z, 0-9, -, _'),
Text::make('Hint', 'hint')->nullable()->sortable()->hint('Не используется на сайте, только для удобства администрирования!'),
Text::make('Value', 'value')->required()->sortable(),
Date::make('Updated at', 'updated_at')->sortable()->hideOnForm(),
];
}

public function rules(Model $item): array
{
return [
'setting_group_id' => 'nullable|exists:setting_groups,id',
'slug' => [
'required',
'max:190',
'regex:/^([a-z0-9\-\_]+)$/i',
'unique:setting_groups,slug',
Rule::unique('settings','slug')->where(function ($query) use ($item) {
return $query->where('id','!=', $item->getKey())
->where('setting_group_id', $item->setting_group_id);
}),
],
'hint' => 'nullable|max:190',
'value' => 'required|max:190',
'slug' => 'required|max:190|regex:/^([a-z0-9\-\_]+)$/i|unique:setting_groups,slug,' . $item->getKey(),
'hint' => 'nullable|max:190',
];
}

public function search(): array
{
return ['id', 'slug', 'hint', 'value'];
return ['id', 'slug', 'hint'];
}

public function filters(): array
{
return [
BelongsToFilter::make(
'Group',
'settingGroup'
),
];
return [];
}

public function actions(): array
Expand Down

0 comments on commit 735e323

Please sign in to comment.