0

Hi I am using the laravel authentication system which is out of the box but I want a behavior in which the user could redirect to his last page after login with user data. For logged in I using bootstrap validator

My login code in js file

    function do_login() {
                frm_name = 'userlogin';
                email = $('#userlogin input[id=email]').val();
                password = $('#userlogin input[id=password]').val();
                _token = $('#userlogin input[id=_token]').val();

                if (email == '' || password == '') {
                    $('#flashMessage').attr('class', 'alert alert-danger');
                    $('#flashMessage').html('Please specify Email and Password');
                } else {
                    var param = 'email=' + email + '&password=' + password + '&_token=' + _token;
                    $.ajax({
                        type: "POST",
                        datatype: "json",
                        url: "/auth/login",
                        data: param,
                        success: function (data) {
                            if (data.status == 0) {
                                $('#loginModal').modal('hide');
                                window.location.href = '/';
                            }
                            if (data.status == 1) {
                                $('#flashMessage').attr('class', 'alert alert-danger');
                                $('#flashMessage').html(data.message);
                            } else {
                                onError(data.Error, '#' + frm_name);
                            }
                        }
                    });
                }
            }

    $(document).ready({
    $('#login').click(function () {
            do_login();
        });
});

So how can I managed the user could redirect to his last page after login using js. Thanks

sandip kakade
  • 1,346
  • 5
  • 23
  • 49

3 Answers3

1
return  redirect::route('route_name')->with('msg_name', 'Message');

you can use the following to redirect back

use Redirect;
Noam Hacker
  • 4,671
  • 7
  • 34
  • 55
Mr Singh
  • 114
  • 9
  • this is d way one can redirect to other page for example on click of login button u can call it in following way n in href give link for your routes of that view page – Mr Singh Dec 20 '16 at 06:15
  • – Mr Singh Dec 20 '16 at 06:16
0

Use the following code:

return Redirect::back();

but before this you must add:

use Redirect
Noam Hacker
  • 4,671
  • 7
  • 34
  • 55
Shubham Bansal
  • 586
  • 6
  • 7
0

you can use http referrer in built php or return redirect()->back(); or Redirect::back();

ujwal dhakal
  • 2,289
  • 2
  • 30
  • 50