示例#1
0
    public function test()
    {
        $orderItems = OrderItem::select(DB::raw('product_id, 
				count(product_id) as count'))->whereRaw('MONTH(created_at)=6')->groupBy('product_id')->take(5)->orderBy('count')->get();
        foreach ($orderItems as $i => $orderItem) {
            echo $orderItem->product->name . '<br>';
        }
    }
示例#2
0
 public function getBestSellingProduct()
 {
     $products = OrderItem::select(DB::raw('product_id, 
             count(product_id) as count'))->whereRaw('MONTH(created_at)=6')->groupBy('product_id')->take(5)->orderBy('count')->get();
     return $products;
 }