Sunday, March 5, 2017

How to save images url and images in laravel 5.3 with ajax?

I have connected on the page welcome.blade.php javascript cropbox that truncates the image. After click on button Crop i get the string like data:image/png;base64,ivBOrwqnmdIo.....................................................................................

I write my function to send with ajax sendAvatar(img) and adding to the bottom of klick event

$('#btnCrop').on('click', function(){

    var img = cropper.getDataURL();                 
    sendAvatar(img);

})

Next i try to send to my web.php with ajax

function sendAvatar(img){ 

  var url = '';
  var token = '{!! csrf_token() !!}';
    $.ajax({

       method: 'POST',
       url: url,
       data: {_token: token, img: img},
       success: function(){
       alert(img);
      }


   });

}

I have a model Avatar.php with field avatar_url

class Avatar extends Model
 {
   protected $fillable=['id','avatar_url'];
 }

Now i try in my web.php store the image in my db

But i don t know how to do this. Please help me

I am use laravel 5.4



via Jaan Pajusalu

Advertisement