0

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?

2
  • Add use Illuminate\Http\Request; at the top of your web.php Commented Feb 20, 2018 at 9:59
  • @kerbholz yes thanks that helped Commented Feb 20, 2018 at 10:23

2 Answers 2

1

To retreive the GET input one needs to write:

Route::get('/user', function(\Illuminate\Http\Request $request){
  dd($request->input('id'));
});
Sign up to request clarification or add additional context in comments.

5 Comments

Not quite true. You are not using any route variables in your route. Route::get('/user/{id}') does use a route variable. It's totally fine to use a route like Route::get('/user.php')
You could even do Route::get('/user.py') or Route::get('/user.html')
@kerbholz I just realized that Route::get('/user.py') or Route::get('/user.html')actually do work! But Route::get('/user.php') doesn't for some reason
I think that has to do with your Apache Rewrite rules. It should work if you stop Apache and use php artisan serve to use PHP's server
@kerbholz your right, please write an answer so I can check it.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.