whitecollar
whitecollar

Reputation: 269

How to get Route URL param in Controller | Laravel

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!

Upvotes: 0

Views: 4579

Answers (1)

dparoli
dparoli

Reputation: 9171

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.

Upvotes: 1

Related Questions