1
I have 3 tables, Client, Budget and Ordemservicos.
$clientes = Cliente::withCount('orcamento')->orderBy('orcamento_count', 'desc')->get();
the code above returns me what I need, but I need the following
need to do a withCount in the table "ordemservico" however there is inside the table of "orcamento" that is related.
needed something like for example...
$clientes = Cliente::withCount(['orcamento','ordemservico'])->orderBy('ordemservico_count', 'desc')->get();
any idea ?
I think it would look something like this:;
$clientes = Cliente::withCount(['orcamento' => function (Builder $query) {
 $query->withCount(['ordemservico']);
}])->orderBy('orcamento_count', 'desc')->get();

– Kayo Bruno
tested gave this mistake bro.. " Argument 1 passed to App Repositories Clientesrepository::App Repositories{closure}() must be an instance of App Repositories Builder, instance of Illuminate D"
– MichaelCosta
i tried doing so... "$clients = Client::withCount('orcamento','orcamento.ordemservico')->orderby('orcamento_count', 'desc')->get();" I think that would be the correct way is not the right way ?
– MichaelCosta