mysql - transform raw query with subqueries to eloquent -
i have following working query subquery works fine transfrom eloquent because persevere other relaiont of user model
select * ( select p.from, a.account_id, count(*) num accounts inner join accounts_prop p on (a.account_id = p.account_id) group p.account_id having num = 1 ) query year(query.von) = 2017
i have user model represented (accounts
table) , property model represented (properites
table)
user -> property
relation 1 many
user
public function properties() { return $this->hasmany('app\property', 'account_id', 'account_id'); }
property
public function user() { return $this->belongsto('app\user', 'account_id'); }
the output should give users have 1 property , property matches current date.
in raw query testing purposes using constant year
actually seems work like
user::wherehas('properties', function($query){ $query = $query->where('von', '=', carbon::now()->format('y-m-d')) ->havingraw('count(account_id) = 1') ->with('department'); })->get();
Comments
Post a Comment