0

I have the following route:

Route::get('/category/{category}/keyword/{keyword}', 'CategoryController@search');

In my controller I am trying to retrieve both the URL params using the following code:

public function search(Request $request)
{
    $request->all();
    ...
}

The above code doesn't return the value of parameters.

If I call the following code, I get the value:

$request->category

Can someone tell me what am I doing wrong?

Thanks!

1
  • You're not doing anything wrong. $request->all() will return an array of form-data (POST) Commented Mar 15, 2017 at 22:11

1 Answer 1

1

Try this:

 public function search($category, $keyword)

or this:

 public function search(Request $request, $category, $keyword)

If you need the Request object.

The route parameters are injected in the funcion call, they are not in the request inputs.

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

3 Comments

I think anything dependancy injected (like the Request) has to be after any segment variables. public function search($category, $keyword, Request $request)
For me its working with injected Request in first position
Also the laravel docs put the injected Request in first position with route parameters, see here at the paragraph "Dependency Injection & Route Parameters": laravel.com/docs/5.4/requests

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.