3

I have a route like this:

Route::get('page/{id},{time}', 'OpController@op');

Now my method is simply:

public function op(Request $request, $id, $time)
{

        dump($request->all());
        dump($id);
}

If I call that with /op/hello,123 I get this dump:

$request->all() -> []
$id -> "hello"

Is there any reasons that $request doesn't have the parameters?

$request->input('id') returns null

1
  • if my answer was helpful, please upvote and choose it as best answer. Commented Mar 21, 2016 at 15:06

3 Answers 3

2

Because Request shouldn't have URL vars in it. Request used for getting data from forms etc. You should use $id and $time variables if you want to get data from URL in this case.

You can contents of Request object by using dd($request);

Sign up to request clarification or add additional context in comments.

1 Comment

@giò - the verb is irrelevant, anything in either the Query String or encoded form data can be collected with a Request input.
2

Got it:

$request->input('param');

Works when url query param, example: url?param=text and all the params of POST.

That doesn't work with route param 'myurl/{param}'

Comments

-1

Just change your route with below code....

Route::get('page/{id}/{time}', 'OpController@op');

And write url like /page/hello/123

1 Comment

, is allowed and works fine in URLs, so it's not a reason why Request doesn't have those vars in it.

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.