Laravel Vue Dropzone.js请求文件返回NULL

问题描述 投票:0回答:1

我有问题,我无法解决。我阅读了很多论坛和问题,但无法解决。

问题是

$photos = $request->file('file'); return var_dump($photos);

带来NULL。我试图找到错误,但我无法

我想将图像存储在服务器上并存储在一个表中,然后将其连接到另一个产品表,首先在输入中写入一些数据ex。名称,类别,在另一个选项卡之后,使用Dropzone上传图像,并一起保存一次。

我正在使用rowanwins dropzone。

我的[[.... blade.php

<form method="POST" enctype="multipart/form-data" action="{{ route('product.createnew') }}"> // Other Products inputs .. //Uploads <vue-dropzone ref="myVueDropzone" id="dropzone" :options="dropzoneOptions"> </vue-dropzone> // / form and scripts section <script> var url = "{{ route('product.createnew') }}"; console.log(url); var app = new Vue({ el: '#app', data: function () { return { dropzoneOptions: { url: url, thumbnailWidth: 150, maxFilesize: 2, maxFiles: 2, acceptedFiles: ".jpeg,.jpg,.png,.gif", autoDiscover : true, clickable : true, uploadMultiple :true, addRemoveLinks:true, headers: { "X-CSRF-TOKEN": document.head.querySelector("[name=csrf-token]").content }, }, radioButton: '0', } }, methods: { deleteDropFile(index) { this.dropFiles.splice(index, 1) }, } });

我的创建控制器

public function create(Request $request) { $validator = Validator::make($request->all(), [ //Other products input 'file' => 'nullable|mimes:jpeg,jpg,png,gif|max:2048', ]); //$products = new Products //$products->save(); $photos = $request->file('file'); return var_dump($photos); if (!is_array($photos)) { $photos = [$photos]; } for ($i = 0; $i < count($photos); $i++) { $photo = $photos[$i]; $savename = sha1(time() . '.' . $request->get('name'))."_$i"; $images = new ProductImages ([ 'name' => $request->get('name'), 'post_id'=> $products->id, 'path'=> public_path('uploads') . '/' . $savename, 'main'=> 0, ]); $images->save(); Image::make($photo) ->resize(250, null, function ($constraints) { $constraints->aspectRatio(); }) ->save(public_path('uploads'). '/' . $savename); $photo->move(public_path('uploads'), $savename); } return redirect()->back(); }

我的路线

Route::group(['prefix' => 'product'], function () { Route::get('/create', 'ProductController@index')->name('product.create'); //View Route::post('/createnew', 'ProductController@create')->name('product.createnew'); //Post });
php laravel vue.js null dropzone.js
1个回答
0
投票
毕竟,我发现了什么问题。是验证

'file' => 'nullable|mimes:jpeg,jpg,png,gif|max:2048',

引发错误。

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.