laravel 相关 eloquent 模型的子句
laravel where Clauses on related eloquent model
嘿,为什么我不能在相关 eloquent 模型上使用带有 3 个参数的 where 子句??
简单示例(我想要 <=)
$user->roles->where('active',1);
//正在工作
$user->roles->where('active','=',1);
//不工作
我可以只在以下情况下使用 3 个参数吗:
DB::table('users')->where('votes', '=', 100)->get();
不在:
$xy->users->where('votes', '=', 100);
谢谢,
$user->roles
是 returning 一个 Collection
,它有一个方法 where
正好接受两个参数:
$user->roles->where("key", "value");
如文档中所示:https://laravel.com/docs/5.4/collections#method-where
如果要使用三个,则需要 return 一个 Query Builder
实例:
$user->roles()->where("key", "operator", "value")->get();
嘿,为什么我不能在相关 eloquent 模型上使用带有 3 个参数的 where 子句??
简单示例(我想要 <=)
$user->roles->where('active',1);
//正在工作
$user->roles->where('active','=',1);
//不工作
我可以只在以下情况下使用 3 个参数吗:
DB::table('users')->where('votes', '=', 100)->get();
不在:
$xy->users->where('votes', '=', 100);
谢谢,
$user->roles
是 returning 一个 Collection
,它有一个方法 where
正好接受两个参数:
$user->roles->where("key", "value");
如文档中所示:https://laravel.com/docs/5.4/collections#method-where
如果要使用三个,则需要 return 一个 Query Builder
实例:
$user->roles()->where("key", "operator", "value")->get();