mercredi 2 septembre 2015

Laravel 5 Ajax File/Image Upload

I have an issue in my laravel ajax application,

I cant upload images/files through ajax POST.

here is my code.

Ajax..

/*Add new catagory Event*/
$(".addbtn").click(function(){
$.ajax({
      url:'add-catagory',
      data:{
        name:$("#catagry_name").val(),
        descrptn:$("#catagry_desc").val(),
        logo:new FormData($("#upload_media_form")[0]),
        visibity:$("#visiblty").val(),
        },
      dataType:'json',
      async:false,
      type:'post',
      success:function(response){
        console.log(response);
      },
    });
 });
/*Add new catagory Event*/

Blade template ...

 <form enctype="multipart/form-data" id="upload_form" role="form" method="POST" action="" >
      <div class="form-group">
        <label for="catagry_name">Name</label>
         <input type="hidden" name="_token" value="{{ csrf_token()}}">
        <input type="text" class="form-control" id="catagry_name" placeholder="Name">
        <p class="invalid">Enter Catagory Name.</p>
      </div>
      <div class="form-group">
        <label for="catagry_name">Logo</label>
        <input type="file" class="form-control" id="catagry_logo">
        <p class="invalid">Enter Catagory Logo.</p>
    </div>

    </form>
    </div>
    <div class="modelFootr">
      <button type="button" class="addbtn">Add</button>
      <button type="button" class="cnclbtn">Reset</button>
    </div>
  </div>

Controller ..

public function catadd(){
    return $file = Input::file('logo');
}

Route ..

 Route::post('add-catagory',['as'=>'catagory_add','uses'=>'MastersController@catadd']);

What is the error in my code ???

I getting error in console like

Uncaught TypeError: Illegal invocation

How can i solve this issue...?



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

Aucun commentaire:

Enregistrer un commentaire