I am designing a RESTful application and I would like to manage url parameters, at the moment I have this function in controller for the GET that list all the resources api/v1/cats:
public function index()
{
$cats = Cats::all();
foreach ($cats as $cat) {
$requirement->view_requirement = [
'href' => 'api/v1/cat/' . $cat->id,
'method' => 'GET'
];
}
$response = [
'msg' => 'List of all Cats',
'cats' => $cats
];
return response()->json($response, 200);
}
and route is :
Route::group(['prefix' => 'v1'], function() {
Route::resource('cats', 'CatController', [
'except' => ['edit', 'create']
]);
which is the best way to manage url with for example search parameter like: api/v1/cats?name=Filip&color=black