I am using Laravel 5.5.13.
My goal is to create an endpoint like this:
/api/items/{name}?kind={kind}
Where kind is optional parameter passed in by the query string.
My current routes in api.php looks like this:
Route::get('items', 'DisplaynameController@show');
My current controller is like this:
public function show(Request $request)
{
if ($request->input('kind') {
// TODO
} else {
return Item::where('name', '=', $request->input('name'))->firstOrFail();
}
}
I
I am currently using $request->input('name') but this means I need to provide ?name=blah in the query string. I am trying to make it part of the route.
May you please provide guidance.