Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

muuucho's avatar
Level 11

Livewire form, validation problem

In my form, name validates correct, but not amount. If I type in a string, like abc into the forms amount field, a 0 is inserted into the database. I expect a validation error to be thrown instead.

<div class="p-6">
    <form wire:submit="save">
        <div>
            <x-input-label for="name" :value="__('Name')" />
            <x-text-input wire:model="form.name" id="name" class="mt-1 block w-full" type="text" />
            <x-input-error :messages="$errors->get('form.name')" class="mt-2" />
        </div>

        <div class="mt-4">
            <x-input-label for="amount" :value="__('Amount')" />
            <x-text-input wire:model="form.amount" id="amount" class="mt-1 block w-full" type="text"/>
            <x-input-error :messages="$errors->get('form.amount')" class="mt-2" />
        </div>

        <div class="mt-4">
            <x-primary-button>
                {{ __('Save') }}
            </x-primary-button>
        </div>
    </form>
</div>

0 likes
3 replies
migsAV's avatar
migsAV
Best Answer
Level 31

@muuucho the rule for the amount has double square brackets.

public function rules(): array
    {
        return [
           // other validation
            'amount' => [
-                ['nullable', 'integer']
+				'nullable', 'integer'
            ],
        ];
    }
1 like
Chingy's avatar

@muuucho I would highly suggest you typehint stuff. Variables like amount should be wire bound to inputs of type number, not text.

Please or to participate in this conversation.