'Want to execute below query into laravel 5.8

I want to execute the below query into laravel 5.8

SELECT
  GROUP_CONCAT(CONCAT('MAX(IF(godown_name = ''', t.godown_name, ''', available_qty, NULL)) AS "',t.godown_name,'"')
  ) INTO @PivotQuery
FROM
  (
    SELECT DISTINCT A.godown_name FROM
    (
        SELECT p.id, p.product_name, g.godown_name, i.available_qty
        FROM products p
        LEFT JOIN inventories i ON i.product_id = p.id
        LEFT JOIN godowns g ON g.id = i.godown_id
    ) A  
  
  ) t;

SET @PivotQuery = CONCAT('SELECT product_name,', @PivotQuery, ' FROM products p
LEFT JOIN inventories i ON i.product_id = p.id
LEFT JOIN godowns g ON g.id = i.godown_id GROUP BY product_name');

PREPARE statement FROM @PivotQuery;
EXECUTE statement;

Please help to get an output of the above query into laravel. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source