laravel - 通过 api 发送的 vuejs 表单数据在 laravel 控制器上不可见
问题描述
看一看
Vue.js
data() {
return {
url: '/api/client/document/upload',
}
},
计算的
attachment() {
return {
slug: 'testing',
test_type[enter image description here][1]: (this.individual === 1)? 'transfer_individual': 'transfer_corporate',
application_id: this.client_investment_id
};
上传方式
upload: function () {
if(!this.validateForm()) {
Message.warning({ message: 'Complete the form and proceed' });
return;
}
if(!this.$refs.upload.uploadFiles[0]) {
Message.warning({ message: 'Upload the form and proceed' });
return;
}
console.log('data', this.attachment);
this.$refs.upload.submit();
},
控制器端 laravel
public function uploadDocument()
{
$input = request()->all();
dd($input);
}
有一个文件正在上传到给定的 url;
当我从控制器 dd 时,我得到一个 null 的 application_id 但如果我在提交之前 console.log 能够查看我的数据。我可能做错了什么。
解决方案
将请求作为参数传递给函数并all()
在请求实例上调用方法。
public function uploadDocument(Request $request)
{
$input = $request->all();
dd($input);
}
要在 public/images 文件夹中获取并保存名称与时间戳连接的文件,请尝试
//Assuming you have the file input name as `photo`
if ($file = $request->file('photo')) {
$name = time() . $file->getClientOriginalName();
$file->move('images/', $name);
}
推荐阅读
- angular - 为什么我的 Eclipse 控制台中有多个 Angular 语言服务器选项卡
- wso2 - 当我们在 WSO2 ESB 中安排任何任务时,我可以通过浏览器将任何参数传递给任务吗?
- sql - 如何获取日期集的(周数,周数)
- npm - npm 或纱线,`node-gyp 重建` npm 错误!退出状态 1
- python - 从输出中删除新行
- java - 从 MQTT 服务器接收消息时,Protobuf Java 方法 parseFrom() 挂起
- azure-machine-learning-studio - Azure 机器学习 FileDataSet 图像 - 分片/拆分到节点
- tree - 从java中的ArrayList构建平衡二叉搜索树
- python - 如何获取列表中项目的字典项目值?Python
- bash - 如何在bash中的数组中查找数字的倍数?