I am currently building a CRUD based REST API out of an existing CakePHP 3.8 application and am working through refining the results against my CRUD endpoints. I see that query strings are the RESTful way of doing this in ansers like this one, for example using queries like this for searching for color, type and doors against a cars resource:
/cars?color=blue&type=sedan&doors=4
I could hard code something like the following pseudo code:
// Binding would be used to handle sql injection in actual code, but this demonstrates my point
$getParameters = $this->request->getQuery();
$query = $this->CarsTable->find('all');
if(array_key_exists('color', $getParameters) {
$query->andwhere(['Cars.color like' => $getParameters['color']]));
}
if(array_key_exists('type', $getParameters) {
$query->andwhere(['Cars.type like' => $getParameters['type']]));
}
if(array_key_exists('doors', $getParameters) {
$query->andwhere(['Cars.doors' => $getParameters['doors']]));
}
But I have a lot of complex objects that this is going to cover and it seems like there would be a more streamlined approach out there for handling this?
I am wondering what would be the most ideal (or at least a more ideal) method of handling this on the query building / CakeORM integration side of things? Or is there a good plugin for streamlining these sorts of queries in CakePHP?
I have been looking at FriendsOfCake/search, which I know is a search tool. But it seems like it may support the type of functionality I am looking at.
Although if there is something more specifically built for transforming query strings into Cake orm queries, I would in learning what that tool is?
Thanks in advance for the help!