lavnishad93
1 month ago
256
8
Laravel

convert a sql query to php laravel query

Posted 1 month ago by lavnishad93

I am new at laravel so i want to convert a query to php laravel query.

SELECT  c.id ,c.name,c.image,c.status,count(pv.id) as product_varients_count, (select count(*) from subcategories as sc where c.id = sc.category_id ) as subcategories_count, (select count(*) from products as p where c.id = p.category_id ) as products_count 
FROM 
    `product_varients` as pv  
left join products as p on pv.product_id = p.id 
left join categories as c on p.category_id = c.id
GROUP BY c.id

Please sign in or create an account to participate in this conversation.