I am building a SPA using Laravel 8 and inertiaJs
I am trying to update records that have a uploaded file (input file). When storing data everything is good, but I have a problem when I try to update with file uploaded.
PS: There is no error showing in the console or from the server. In network tab I see the message "Failed to load response", and like a result, the required fields show errors, it's like I sent an empty data.
see image : Image showing the errors
This is my code:
web.php
Route::put('/software/{software}', [SoftwareController::class, 'update'])->name('software.update');
SoftwareController
public function update(Request $request, Software $software)
{
$data = $request->validate([
'name' => 'required',
'software_version' => 'nullable',
'doc_ref' => 'nullable',
'doc_version' => 'nullable',
'doc_name' => 'required_with:doc_ref',
'doc_filename' => 'nullable|file|mimes:docx,doc,xlsx,xls,pdf,jpg,png',
]);
$doc_filename = $request->file('doc_filename') ? $request->file('doc_filename')->store('software/equipment', 'public') : null;
$software->update(array_merge($data, ['doc_filename' => $doc_filename]));
return Redirect::back()->with('success', 'Software updated.');
}
Edit.vue
updateSoftware(){
if (confirm("Do you want to update the software ?")) {
this.$inertia.put(this.route('software.update',
{software : this.software_id}), this.form);
}
},
PS:
this.form : contain the data related to v-model
this.software_id : contain the id of the current instance.