Level 122
form data is not validating correctly
is vague to say the least!
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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.
data() {
return {
showModal: false,
loading: false,
newFormRequest: useForm({
items: [],
depot_id: null,
emplacement_id: null
}),
}
},
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
}
})
},
public function saveSupply(StoreSupplyRequest $request): RedirectResponse
{
$this->stockService->saveSupply($request->validated());
$this->notifyModelUpdate(ModelType::Stock, 'update');
return back();
}
[
'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',
]
]
Please or to participate in this conversation.