Skip to content

Commit

Permalink
Fix stubs moonshine filters
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvenga committed Dec 16, 2022
1 parent e82b63d commit b009e2a
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions stubs/MoonShine/Resources/SettingGroupResource.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,72 @@ 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\SettingGroup;
use VI\LaravelSiteSettings\Models\Setting;

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

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

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 [
'slug' => 'required|max:190|regex:/^([a-z0-9\-\_]+)$/i|unique:setting_groups,slug,' . $item->getKey(),
'hint' => 'nullable|max:190',
'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',
];
}

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

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

public function actions(): array
Expand Down

0 comments on commit b009e2a

Please sign in to comment.