本文介绍了Laravel 5.4中的Dropzone.js发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我未通过控制器的uploadGallery方法收到任何请求.虽然,邮寄请求已正确接收.

I am not receiving any request at controller's uploadGallery method. Although, the post request is received correctly.

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函数内的所有内容均未运行.为什么?

Anything inside the uploadImages function is not running. Why?

推荐答案

uploadImages()函数中的类型提示错误.

You have wrong type hinting in your uploadImages() function.

public function uploadImages(Image $request)

public function uploadImages(Request $request)

现在,您应该可以使用request()抓取文件了.

Now you should be able to use request() to grab files.

这篇关于Laravel 5.4中的Dropzone.js发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:01