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

mostafa-amine's avatar

Data Not Validating Correctly in Laravel Vue Application

I'm facing an issue in my Laravel Vue application When I attempt to submit a form with empty inputs, the validation process unexpectedly succeeds, allowing the form to be submitted despite the absence of required data.

Frontend

data

    data() {
        return {
            showModal: false,
            loading: false,
            newFormRequest: useForm({
                items: [],
                depot_id: null,
                emplacement_id: null
            }),
        }
    },

methods

saveSupplyRequest() {
            this.loading = true;

            this.newFormRequest.items = this.newFormRequest.items.map((item) => {
                return {
                    'product': item.product,
                    'product_id': item.product?.id,
                    'lots': item.lots,
                    'price': item.price,
                    'quantity': item.quantity
                }
            })

            this.newFormRequest.post(route('stocks.supply.save'), {
                preserveScroll: true,
                onSuccess: () => {
                    this.closeModal();
                },
                onFinish: () => {
                    this.loading = false
                }
            })
        },

Backend

controller

    public function saveSupply(StoreSupplyRequest $request): RedirectResponse
    {
        $this->stockService->saveSupply($request->validated());

        $this->notifyModelUpdate(ModelType::Stock, 'update');

        return back();
    }

validation rules array

[
            'depot_id' => [
                'required',
                'integer',
                'exists:depots,id',
            ],
            'emplacement_id' => [
                'required',
                'integer',
                'exists:emplacements,id'
            ],
            'items' => [
                'required',
                'array',
            ],
            'items.*.product_id' => [
                'required',
                'integer',
                'exists:products,id',
            ],
            'items.*.quantity' => [
                'required',
                'integer',
            ],
            'items.*.price' => [
                'required',
                'numeric'
            ],
            'items.*.lots' => [
                'nullable',
                'array',
            ],
            'items.*.lots.*.id' => [
                'nullable',
                'integer',
                'exists:lots,id',
            ],
            'items.*.lots.*.quantity' => [
                'nullable',
                'integer',
            ],
            'items.*.lots.*.name' => [
                'required',
                'string',
            ],
            'items.*.lots.*.production_date' => [
                'required',
                'date',
            ],
            'items.*.lots.*.expiration_date' => [
                'required',
                'date',
            ]
        ]
0 likes
1 reply
Snapey's avatar

form data is not validating correctly

is vague to say the least!

1 like

Please or to participate in this conversation.