FilamentF
Filamentβ€’3y ago
sijicc

validation messages under fields not showing

Hi, I have CreateCompany Form component, and validation&model creation is in separate Action CreateCompany. Data is being held in livewire Component $company variable using ->statePath('company'). Problem is - validation is happening for name, website, but filament expects validation messages for company.name company.website. Can I get around this in an easy way, or do I have to do some sheananigans?

Related code:
$validated = Validator::make($company, [
            'name' => ['required', 'max:255'],
            'nip' => ['required', new NipRule(), 'unique:companies,nip'],
            'regon' => ['required', new RegonRule(), 'unique:companies,regon'],
            'krs' => ['max:10', 'nullable'],
            'website' => ['url', 'nullable'],
        ])->validate()
return Company::create($validated)


    public function form(Form $form): Form
    {
        return $form
            ->schema([
                Fieldset::make(__('Basic info'))->schema([
                    TextInput::make('name')
                        ->required(),
                    TextInput::make('nip')
                        ->required(),
                    TextInput::make('regon')
                        ->required(),
                    TextInput::make('krs'),
                    TextInput::make('email'),
                    TextInput::make('phone'),
                ])
            ])
            ->statePath('company');
    }


public function submit(\App\Actions\CreateCompany $createCompany): RedirectResponse|Redirector
    {
        $createCompany->handle($this->company);

        return redirect()->route('companies.index');
    }


And here is validation messages working for company., but not showing without company.
Also probably should mention that if i add company.
to Validator, it doesn't work πŸ™‚
image-1.png
image.png
Was this page helpful?