Reputation: 11
I have problems with getting Laravel URL.
I have one page that if user is not logged in, it redirect user to wrong url and it's giving an error.
I'm using redirect()->intended($this->redirectPath());
to get back user where he was on page after login, so somehow I have to write code that will check what is the redirect URL, and if it's the URL that will give an error,
I know what is the URL, it must redirect user to another URL that I need to set.
I tried different methods taking
$this->redirectPath() == 'here goes the url'
and like
redirect()->intended($this->redirectPath()) == 'again url here'
But nothing works.
Upvotes: 1
Views: 3775
Reputation: 7571
You have to understand what redirect()->intended()
actually does.
It looks for a session variable named url.intended
like session()->pull('url.intended')
(note that pull()
will remove the variable after this call, which is handy because you usually only need this variable once).
This variable is currently only set when you call redirect()->guest('/yourpath')
(it will set your current URL as the url.intended
), unless you manually set it in your own logic using session()->put('url.intended')
.
So the most obvious way to use this is to use redirect()->guest('/login')
, and then after the user has successfully logged in you may use redirect()->intended()
(without parameter) to redirect the user back to the page that originally sent him to the login page.
Upvotes: 1
Reputation: 3594
Try this:
return Redirect::intended('here goes the url');
Or
return Redirect::intended();
intended()
checks if the session index url.intended exists and redirects to it by default or else redirect to $default='/' which can be overwritten.
Upvotes: 1