Error: The part name field is required, The part number field is required, the image field is required.
async submit(form) {
const forms = new FormData();
const keys = Object.keys(form);
keys.forEach((key) => forms.append(key, form[key]));
// appends image
this.$refs.upload.uploadFiles.forEach(({ raw }) => forms.append("image", raw));
try {
this.loading = true;
const { id } = form;
const {
data: { message },
} = id
? await this.$axios.put(`/api/inventory_transactions/${id}`, forms)
: await this.$axios.post("/api/inventory_transactions", forms);
this.$notify.success(message);
this.$emit("success");
this.close();
} catch ({ response }) {
this.errors = response?.data?.errors || {};
} finally {
this.loading = false;
}
},
Here is my Controller and how I validate all the fields. I need your help guys. Thank you. I think my the axios is the problem. I wasted a lot of time just fixing this
public function update(Request $request, $id)
{
$inventory_transaction = $request->validate($this->validation());
$value = Inventory_transaction::withTrashed()->findOrFail($id);
if($request->hasFile('image')) {
$filename = uniqid() . '.' . $request->image->extension();
Storage::putFileAs('inventory_transactions', $request->image, $filename);
$inventory_transaction['image'] = $filename;
}
$value->update($inventory_transaction);
return $this->respondWithMessage('Transaction successfully updated.');
}
private function validation()
{
return [
'part_name' => ['required'],
'part_number' => ['required'],
'unit' => ['required'],
'category' => ['required'],
'sub_category' => ['required'],
'unit_price' => ['required'],
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'brand' => ['required'],
'serial_number' => ['required'],
'specifications' => ['required'],
'remarks' => ['required'],
];
}