dongshi1148 2014-06-21 10:02
浏览 54

URI中的Laravel条件

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

  • 写回答

1条回答 默认 最新

  • dt3358 2014-06-21 10:15
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计