public function index() { $userName = Auth::user()->name; $campains = Campain::all(); $positiveROI = 0; $negativeROI = 0; foreach ($campains as $campain) { $cost = $campain->cost; $gain = $campain->gain; $roi = ($gain - $cost) / $cost; if ($roi > 0) { $positiveROI++; } else { $negativeROI++; } } $campainsA = $campains->toArray(); $campainsA = array_reverse($campainsA); $max = 5; if (count($campainsA) < 5) { $max = count($campainsA); } $indexValues = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]; for ($i = 0; $i < $max; $i++) { $cost = $campainsA[$i]["cost"]; $gain = $campainsA[$i]["gain"]; $indexValues[$i][0] = $cost; $indexValues[$i][1] = $gain; } return view('dashboard', ['userName' => $userName, 'positiveROI' => $positiveROI, 'negativeROI' => $negativeROI, 'lastFive' => $indexValues]); }
public function roi() { $userName = Auth::user()->name; $campains = Campain::all(); $resp = array(); foreach ($campains as $campain) { $id = $campain->id; $cost = $campain->cost; $gain = $campain->gain; $roi = ($gain - $cost) / $cost; $resp[$id] = $roi; } arsort($resp); $report = []; foreach ($resp as $key => $value) { $roi = number_format($value, 2); $campain = Campain::find($key); $lists = DB::table('links')->where('campain_id', '=', $key)->get(); $keywords = []; foreach ($lists as $list) { $keyword_id = $list->keyword_id; $keyword = Keyword::find($keyword_id); $keywords[] = $keyword->text; } $report[] = ["campain" => $campain->description, "roi" => $roi, "keywords" => $keywords]; } return view('report.roi', ['userName' => $userName, 'reports' => $report]); }
public function index() { $userName = Auth::user()->name; $campains = Campain::all(); return view('campain.index', ['userName' => $userName, 'campains' => $campains]); }