jeudi 28 avril 2016

integrate Dropzone.js in Laravel 5.2

In my laravel 5.2 project I need to create a multi file upload area. I choose Dropzone.js Now my problem is how to use this plugin with laravel.

this is my view:

<div class="tab-pane" id="tab_2">
                <div class="box-body">
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">Facebook:</label>
                        <div class="col-sm-10">
                            <input type="text" name="facebook" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">Twitter:</label>
                        <div class="col-sm-10">
                            <input type="text" name="twitter" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="video" class="col-sm-2 control-label">Video:</label>
                        <div class="col-sm-10">
                            <input type="text" name="video" class="form-control">
                        </div>
                    </div>

                    <!--File Upload-->


        <div class="dropzone" id="dropzoneFileUpload">
        </div>



 <script type="text/javascript">
        var baseUrl = "";
        var token = "";
        Dropzone.autoDiscover = false;
         var myDropzone = new Dropzone("div#dropzoneFileUpload", {
             url: baseUrl+"/dropzone/uploadFiles",
             params: {
                _token: token
              }
         });
         Dropzone.options.myAwesomeDropzone = {
            paramName: "file",
            maxFilesize: 2, // MB
            addRemoveLinks: true,
            accept: function(file, done) {

            },
          };
     </script>

my controller:

    public function store(SpotFormRequest $request) {
     $user = Auth::user();
     $role = $user->role;
     if($role === 'manager'){
         $idagent = 1;
         $idmanager = $user->id;
     }
     else{
         $idagent=$user->id;
         $idmanager=0;
     }


    $spot = new Spot(array(
        'agent_id'=>$idagent,
        'manager_id'=>$idmanager,
        'name' => $request->get('spotname'),
        'address' => $request->get('address'),
        'zip' => $request->get('zip'),
        'city'=>$request->get('city_id'),
        'phone' => $request->get('phone'),
        'mobile' => $request->get('mobile'),
    ));
    $spot->save();

    return redirect('/administrator/spot-new')->with('status', 'Your spot has been created!');
}

I need to integrate the upload in the controller.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1SMmmjq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire