Adam
Adam

Reputation: 29039

Laravel: Handle old url with get parameter

Before using Laravel I had a link like this:

/user.php?id=13

In Laravel I have rewritten the url to /user/13. However, I also want to maintain the old url for a couple of month. How can I retrieve it?

If I try

Route::get('/user.php', function(){
 dd("test"); 
});

then he cannot find the route, I guess because of the dot ., this is the result:

No input file specified.

If I try

Route::get('/user', function(Request $request){
  dd( $request->input('id'));
});

then /user?id=29 causes:

Call to undefined method Illuminate\Support\Facades\Request::input()

Although it is stated in the docs

Regardless of the HTTP verb, the input method may be used to retrieve user input

So how can I get the route user.php?id=13 and how to retrieve the input?

Upvotes: 0

Views: 692

Answers (2)

Adam
Adam

Reputation: 29039

To retreive the GET input one needs to write:

Route::get('/user', function(\Illuminate\Http\Request $request){
  dd($request->input('id'));
});

Upvotes: 1

user8034901
user8034901

Reputation:

To make

Route::get('/user', function(Request $request){
  dd( $request->input('id'));
});

work you need to add use Illuminate\Http\Request; at the top of your web.php

Upvotes: 0

Related Questions