*/ public function rules(): array { $service = $this->route('service'); $creating = ! $service instanceof Service; $sometimes = $creating ? 'required' : 'sometimes'; return [ 'title' => [$sometimes, new Translatable(requireDefaultLocale: $creating, max: 255)], 'slug' => [ $sometimes, new Translatable(requireDefaultLocale: $creating, max: 255), new UniqueTranslatedSlug(Service::class, $service?->id), ], 'tagline' => ['sometimes', 'nullable', new Translatable(max: 255)], 'description' => ['sometimes', 'nullable', new Translatable], 'meta_title' => ['sometimes', 'nullable', new Translatable(max: 60)], 'meta_description' => ['sometimes', 'nullable', new Translatable(max: 160)], // A name from the icon set the frontend resolves, e.g. `support`. 'icon' => ['sometimes', 'nullable', 'string', 'max:120'], 'is_featured' => ['sometimes', 'boolean'], 'position' => ['sometimes', 'integer', 'min:0'], 'is_published' => ['sometimes', 'boolean'], 'published_at' => ['sometimes', 'nullable', 'date'], 'unpublish_at' => ['sometimes', 'nullable', 'date', 'after:published_at'], 'technology_ids' => ['sometimes', 'array'], 'technology_ids.*' => ['integer', 'distinct', Rule::exists('technologies', 'id')], 'project_ids' => ['sometimes', 'array'], 'project_ids.*' => ['integer', 'distinct', Rule::exists('projects', 'id')->whereNull('deleted_at')], ]; } public function withValidator(Validator $validator): void { $this->guardPublication($validator, 'services.publish', ['is_published', 'published_at', 'unpublish_at']); } }