Skip to content
Advertisement

How to multiple withcount() columns sum and order by in laravel

I have to need to order by records based on withcount() function in laravel 6

JavaScript

In this code, I have two withCount() functions and I need to order By based on that two-column sum before get(). It works when order by using one column but if I use two-column then it returns an unknown column. Is it possible or not?

Advertisement

Answer

In this case you need to use orderByRaw for your custom expressions

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement