Reputation: 21
I am planning to implement an api for a database using Laravel and I am hoping to have a search function using a URI like
www.exaample.com/WaferSearch?{search string}
It seems very easy to implement a search string like
param1 = 4
This would request a list of wafers ( this is what the database is about) where param1 is equal to 4
The documentation seems to be very clear about how I can turn any sort of a question like this into SQL.
However, I want to have a search string like
param1 > 4
I would also be happy to express the search string like this
param1_GreaterThan =4
and I can see how I could write some code to parse the search string to work out what was required. However I feel that I would be solving a problem that must have been solved many times before.
Is there a well established way to do this?
Graham
Upvotes: 2
Views: 105
Reputation: 14620
There's lots of ways to implement something like this but one way springs to mind as the most extensible. Use two variables in the query.
Greater than
http://myapi.com/wafersearch?p1=4&op=gt
Less than
http://myapi.com/wafersearch?p1=4&op=lt
Equal to
http://myapi.com/wafersearch?p1=4&op=eq
Alternatively you could use rewrites to pass in the variables directly to the route / controller method.
Greater than
http://myapi.com/wafersearch/gt/4
Less than
http://myapi.com/wafersearch/lt/4
Equal to
http://myapi.com/wafersearch/eq/4
Upvotes: 2