vendredi 22 juin 2018

Displaying dynamic data into charts.js with laravel 5.5

I want to display the quantity sold per each product using the below query. From this query I am getting each product id and the quantity sold. The problem is that I want to get by name so that I am able to display it in the pie chart. I have a relationship in BakeryOrderItem but I dont know how to use it in this case. I should be able to do something like BakeryOrderItem()->product->name.

//returns quantity of each product sold

 $product_quantities = BakeryOrderItem::whereBetween('created_at', array(date('2018-01-01'), date('2018-03-31')))
        ->select('product_id', DB::raw("SUM(quantity) as qty"))
        ->groupBy('product_id')
        ->orderBy('qty', 'desc')
        ->take(6)
        ->get();

On this second query I need to display a line in the line chart for each product. The chart should show a line for the top 6 product sold for January, February and march.

//returns number of products sold per month
    $product_details = BakeryOrderItem::whereBetween('created_at', array(date('2018-01-01'), date('2018-03-31')))
        ->select(DB::raw("to_char(created_at, 'Mon') as month"),
            DB::raw("SUM(quantity) as qty"))
        ->groupBy('month')
        ->orderBy('qty', 'desc')
        ->take(6)
        ->get();



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

Aucun commentaire:

Enregistrer un commentaire