*/ public function rules(): array { return array_replace([ 'category_id' => ['required', 'bail', 'integer', Rule::exists('categories', 'id')->withoutTrashed()->where('level', 'category')], 'name' => ['required', 'string', 'max:120'], 'slug' => ['nullable', 'string', 'max:140'], 'status' => ['required', Rule::enum(ProductStatus::class)], 'price' => ['required', 'numeric', 'min:0', 'decimal:0,2', 'max:99999999.99'], 'compare_at_price' => ['nullable', 'numeric', 'min:0', 'decimal:0,2', 'max:99999999.99'], 'cost_price' => ['nullable', 'numeric', 'min:0', 'decimal:0,2', 'max:99999999.99'], 'photos_existing' => ['nullable', 'array'], 'photos_existing.*' => ['string'], 'photos_new' => ['nullable', 'array', 'max:20'], 'photos_new.*' => ['image', 'dimensions:max_width=8000,max_height=8000', 'max:5120'], 'video_url' => ['nullable', 'string', 'max:500', 'url'], 'description' => ['nullable', 'string', 'max:2000'], 'size_chart' => ['nullable', 'file', 'mimes:pdf,docx,xlsx,csv,txt,jpg,jpeg,png,webp,zip', 'extensions:pdf,docx,xlsx,csv,txt,jpg,jpeg,png,webp,zip', 'max:5120'], 'is_featured' => ['required', 'boolean'], 'specs' => ['nullable', 'array', 'max:100', new KeyValueKeys(100)], 'specs.*' => ['nullable', 'string', 'max:1000'], 'tag_ids' => ['nullable', 'array'], 'tag_ids.*' => ['integer', Rule::exists('tags', 'id')], 'tag_new' => ['nullable', 'array', Rule::prohibitedIf(fn (): bool => Gate::denies('tag.create'))], 'tag_new.*' => ['string', 'max:255'], // crud:rules ], $this->modeRules(), $this->customRules()); } /** * What only one mode checks — the Store or Update request's own. * * @return array */ protected function modeRules(): array { return []; } /** The one point where creating and updating part ways. */ abstract protected function unique(string $column): Unique; /** * `unique` counts rows in the trash, so a value can be refused by a record * no screen is showing; this says so. * * @return array */ public function after(): array { return [ fn (Validator $validator) => TrashedConflict::explain( $validator, Product::class, ['sku'], ), ]; } // crud:custom — yours: `make:crud --force` keeps everything between these // two markers. Rules the schema cannot state go in customRules(). /** * Get the rules written by hand, for what the schema cannot state. * * @return array */ protected function customRules(): array { return []; } // crud:custom:end }