Reputation: 3
Hey why i cant use a where clause with 3 params on related eloquent models??
simple example (i want it for a <=)
$user->roles->where('active',1);
//is working
$user->roles->where('active','=',1);
//is not working
Can i use it with 3 params only in:
DB::table('users')->where('votes', '=', 100)->get();
and not in:
$xy->users->where('votes', '=', 100);
Thanks,
Upvotes: 0
Views: 145
Reputation: 29278
$user->roles
is returning a Collection
, which has a method where
on it that accepts exactly two parameters:
$user->roles->where("key", "value");
As seen in the documentation: https://laravel.com/docs/5.4/collections#method-where
If you want to use three, you'll need to return a Query Builder
instance:
$user->roles()->where("key", "operator", "value")->get();
Upvotes: 2