Home > Mobile >  Laravel 8: Redirect in route, preserving one parameter
Laravel 8: Redirect in route, preserving one parameter

Time:11-30

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 Illuminate\Support\Facades\Request::query()"

CodePudding user response:

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

CodePudding user response:

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

url()->previous();

  • Related