使用使用laravel和inertiaJs上载的文件更新数据时加载响应数据失败
我正在用Laravel 8和inertiaJs建造一个水疗中心 我正在尝试更新已上载文件(输入文件)的记录。 当存储数据时,一切都很好,但是当我尝试更新上传的文件时,我遇到了一个问题 PS: 控制台中或服务器中没有显示错误。在网络选项卡中,我看到消息“加载响应失败”,与结果类似,必填字段显示错误,就像我发送了一个空数据 如图所示: 这是我的代码: web.php使用使用laravel和inertiaJs上载的文件更新数据时加载响应数据失败,laravel,vue.js,inertiajs,Laravel,Vue.js,Inertiajs,我正在用Laravel 8和inertiaJs建造一个水疗中心 我正在尝试更新已上载文件(输入文件)的记录。 当存储数据时,一切都很好,但是当我尝试更新上传的文件时,我遇到了一个问题 PS: 控制台中或服务器中没有显示错误。在网络选项卡中,我看到消息“加载响应失败”,与结果类似,必填字段显示错误,就像我发送了一个空数据 如图所示: 这是我的代码: web.php Route::put('/software/{software}', [SoftwareController::class, 'upd
Route::put('/software/{software}', [SoftwareController::class, 'update'])->name('software.update');
软件控制器
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.');
}
编辑.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:
此表单:包含与v型相关的数据
this.software\u id:包含当前实例的id。您遇到的问题可能是您使用的是
PUT
方法,HTML表单使用多部分/表单数据
请求默认不支持该方法,我打赌您在存储正在工作的文件时使用的是POST
尝试使用post添加,但将此
添加到表单中
或者,您可以将更新方法更改为:
updateSoftware(){
if (confirm("Do you want to update the software ?")) {
this.$inertia.post(this.route('software.update',
{software : this.software_id,
_method: 'put',
}), this.form);
}
},
查看有关如何欺骗该方法的文档
并阅读如何正确上传惯性图像