|string> */ public function rules(): array { $menuGroupId = $this->route('menu_group')?->id; $isMaster = $this->user()?->isMasterAdmin() ?? false; $tenantId = $isMaster ? ($this->exists('tenant_id') ? $this->input('tenant_id') : $this->route('menu_group')?->tenant_id) : $this->route('menu_group')?->tenant_id; return [ 'tenant_id' => [ $isMaster ? 'nullable' : 'prohibited', 'integer', 'exists:tenants,id', ], 'name' => [ 'required', 'string', 'max:100', Rule::unique('menu_groups', 'name') ->where(fn ($query) => $tenantId ? $query->where('tenant_id', $tenantId) : $query->whereNull('tenant_id')) ->ignore($menuGroupId), ], 'description' => [ 'nullable', 'string', ], 'is_active' => [ 'nullable', 'boolean', ], ]; } protected function prepareForValidation(): void { $this->merge([ 'is_active' => filter_var( $this->is_active, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ), ]); } }