用于向Fluent / Eloquent查询添加约束的语法

时间:2014-03-21 15:35:07

标签: syntax laravel-4 eloquent fluent

我已经看到了这两种语法,用于向现有的Fluent / Eloquent $查询添加约束(例如在基于条件附加约束时):

$query = $query->where( 'id','=',1 );

$query->where( 'id','=',1 );

它们之间是否存在实际差异?

1 个答案:

答案 0 :(得分:0)

完全没有区别。在这种情况下,$ query是一个对象,它将在内部设置过滤器,但它也返回自己,以提供链接:

$query->where( 'id','=',1 )->where( 'name','=', 'antonio' );

所以这两者完全一样。

$query = $query->where( 'id','=',1 );
$query->where( 'id','=',1 );