A
A
Alexander Ivanov2018-10-05 13:44:26
Laravel
Alexander Ivanov, 2018-10-05 13:44:26

What is the best way to overwrite subquery on builder in laravel?

$query = Name::query()
  ->selectRaw('count(*) as subs, 
(SELECT count(*) FROM customers where active = 0 order by updated_at) as unsubs, sum(device = 1) as pc, 
sum(device = 0) mob');

That that I transfer in crude request the subquery does not look very good. Trying to understand better rewrite it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gerasimov, 2018-10-05
@mrTeo

Use withCount with a closure - https://laravel.com/docs/5.7/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question