I want to redirect to route with name doug-test, but I want to preserve the url parameter. I saw a webpage that says use $request->query(‘url’) to get the url parameter, but that doesn’t seem to work. I want to know the value of the get parameter "url".
For example, if someone goes /login?url=/xyz
I want them redirected to /dougs-page?url=/xyz where /dougs-page is a route named "doug-test"
Here’s what I have so far:
Route::get('/login', function (Request $request) {return redirect()->route('doug-test', ['url'=> $request->query('url')]);})->middleware('not-auth')->name('login');
The error I’m getting is "Call to undefined method IlluminateSupportFacadesRequest::query()"
2
Answers
Nevermind. Taking a closer look at the docs for Request, I see query() is a static method. This works:
I think this one answers your question. How to get the http referer in laravel?
url()->previous();