Given this chunk of ajax that calls FriendsController@destroy
$.ajax({
    url:     '/dashboard/friends/' + id,
    type:    'DELETE',
    data:    { src: 'show' },
    success: function(response) {
    }
});
How can I return Redirect::route('dashboard.friends.index') inside FriendsController after the delete procedure is completed? I guess this is trying to return the response back to AJAX which doesn't know how to react.
I could just window.location.href = '/dashboard/friends' but I want to Flash a success message to the view which I can't do with AJAX.
i know this might be old question but if you want to return a dynamic route
return route('post.view', ['id' => $result]);
and in your front-end you will do
  success: function(response){
          window.location.replace(response);
          }
                        I found the most easiest way of doing this. just use same url again in your ajax success. assuming friends is your route name then
$.ajax({
    url:     '/dashboard/friends/' + id,
    type:    'DELETE',
    data:    { src: 'show' },
    success: function(response) {
       window.location.href = "friends";
    }
});
this way you can just put redirect or flash session message if you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With