我没有收到控制器的uploadGallery方法的任何请求。虽然,正确收到了邮件请求。
gallery.blade.php
<div class="row">
<form action="{{ url('file-upload') }}" method="post" class="dropzone" id="my-awesome-dropzone">
{{ csrf_field() }}
<div class="dz-message">
<h3>Drop images here or click to upload.</h3>
</div>
</form>
</div>
<script type="text/javascript">
$(function (){
Dropzone.options.myAwesomeDropzone = {
paramName: "files",
uploadMultiple:true,
maxFilesize:6,
autoProcessQueue: true,
uploadMultiple: true,
addRemoveLinks: true,
acceptedFiles: ".png, .jpg, .jpeg",
dictFallbackMessage:"Your browser does not support drag'n'drop file uploads.",
dictRemoveFile: "Remove",
dictFileTooBig:"Image is bigger than 6MB",
accept: function(file, done) {
console.log("Uploaded");
done();
},
init:function() {
/* var submitButton = document.querySelector('#submit-all')
myAwesomeDropzone = this;
submitButton.addEventListener("click", function(
myAwesomeDropzone.processQueue();
));
this.on("addedfile", function(){
$('#submit-all').show();
});*/
},
success: function(file,done){
console.log("All files done!");
}
}
});
</script>
web.php
Route::get('/gallery', 'PagesController@Gallery');
Route::post('/file-upload', 'ImagesController@uploadImages');
ImagesController.php
<?php
namespace App\Http\Controllers;
use App\User;
use App\Image;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ImagesController extends Controller
{
public function __construct() {
$this->middleware('auth');
}
public function uploadImages(Image $request) {
$images = request()->file('files');
dd($images);
return view('Gallery');
}
}
uploadImages功能中的任何内容都没有运行。为什么?
答案 0 :(得分:1)
uploadImages()
功能中的类型提示错误。
从
更改uploadImages()
public function uploadImages(Image $request)
到
public function uploadImages(Request $request)
现在您应该可以使用request()
来抓取文件了。
答案 1 :(得分:0)
更改此
public function uploadImages(Image $request) {
$images = request()->file('files');
dd($images);
return view('Gallery');
}
并使用$ request替换request(),因为您使用了eloquent。
public function uploadImages(Request $request) {
$images = $request->file('files');
dd($images);
return view('Gallery');
}
有关与laravel dropzone的更详细集成,您可以参考本教程Integrating Dropzone.js in Laravel 5 applications