samedi 23 décembre 2017

Converting laravel raw SQL queries to collections

I am trying to use http://ift.tt/2BFXxq1 package to display charts in my laravel project but I noticed that I require the use of models/collections for it (the database) part to work. Here is a sample from the documentation

$chart = Charts::database(User::all(), 'bar', 'highcharts');

Now, I am not using eloquent ORM for my queries, I instead use raw queries. I don't know how to convert this particular query have such that it returns a collection instead of an array it currently returns

$result = DB::select("SELECT DATE(a.created_at) as date, SUM(a.credit) as credit, SUM(a.debit)
        FROM telco_transactions AS a
        WHERE a.telco_id = '1' and DATE(a.created_at) BETWEEN DATE(NOW())-INTERVAL 7 DAY AND DATE(NOW())
        GROUP BY DATE(a.created_at)");



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zmA3Az
via IFTTT

Aucun commentaire:

Enregistrer un commentaire