使用laravel雄辩或流利的语言,我可以使用('fo',$bar)或('o','=','$bar')查询数据库
例如:
$var = DB::table('users')->where('foo', $bar)->get();
与
$var = DB::table('users')->where('foo', '=', $bar)->get();
据我所知,这两种方法都有效,但我的问题是:
我应该使用其中一个而不是另一个吗?为什么
例如,我会在一个问题上遇到我不会遇到的问题吗?或者两者都安全吗?
它们是一回事。从Query Builder.php文件:
// If the given operator is not found in the list of valid operators we will
// assume that the developer is just short-cutting the '=' operators and
// we will set the operators to '=' and set the values appropriately.
换句话说,"="是默认值,从拉拉威尔的角度来看没有什么区别。
您可能想要使用"="的唯一原因是为了让浏览代码的其他开发人员更容易阅读,因为您已经明确说明了"where foo equals boo"