Laravel redirect to route from controller when called by AJAX

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.


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);
          }

Tags:

Php

Laravel