skip to Main Content

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


  1. Chosen as BEST ANSWER

    Nevermind. Taking a closer look at the docs for Request, I see query() is a static method. This works:

    Route::get('/login', function (Request $request) {return redirect()->route('doug-test', ['url'=> $request::query('url')]);})->middleware('not-auth')->name('login');
    

  2. I think this one answers your question. How to get the http referer in laravel?

    url()->previous();

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search