public function index($username) { $user = User::where('username', $username)->firstOrFail(); $id = $user->id; $transactions = Transactions::where('user_id', '=', $id)->orderBy('created_at', 'desc')->take(5)->get(); return view('user.profile', compact('user', '=', 'userCurrency', 'transactions')); }
private function getSalesInfo($month) { $result = array(); $buyers = array(); $buyers_total = array(); $data = Transactions::where(DB::raw('MONTH(created_at)'), '=', $month)->get(); foreach ($data as $t) { $buyers = array_add($buyers, $t->buyer->name, Transactions::where(DB::raw('MONTH(created_at)'), '=', $month)->where('buyer_id', $t->buyer->id)->count()); $buyers_total = array_add($buyers_total, $t->buyer->name, Transactions::where(DB::raw('MONTH(created_at)'), '=', $month)->where('buyer_id', $t->buyer->id)->sum('sub_total')); } $result = array_add($result, 'buyers', $buyers); $result = array_add($result, 'buyers_total', $buyers_total); return $result; }