"Get" route with query string and custom params

The $name variable is a route param, not a query param, this means that you can pass it directly to the function as an argument.

So, if your route is like this:

Route::get('items/{name}', 'DisplaynameController@show'); 

Your function should be like this:

public function show(Request $request, $name) // <-- note function signature
{   //                                 ^^^^^
    if ($request->has('kind'))
    {
        // TODO
    }
    else
    {
        return Item::where('name', '=', $name)->firstOrFail(); // <-- using variable
    }   //                              ^^^^^
}

Another option is to get the variable as a Dynamic Property like this:

public function show(Request $request)
{
    if ($request->has('kind'))
    {
        // TODO
    }
    else
    {
        return Item::where('name', '=', $request->name)->firstOrFail();
    }   //                              ^^^^^^^^^^^^^^
}

Notice that we access the name value as a dynamic property of the $request object like this:

$request->name

For more details, check the Routing > Route parameters and Request > Retrieving input sections of the documentation.


As stated in the documentation you should do:

public function show($name, Request $request)

Laravel will take care of the variable binding