Edit File: HomeController.php
<?php namespace App\Http\Controllers\Admin; use App\Models\Admin; use App\Models\Order; use App\Models\Store; use Carbon\Carbon; use App\Models\City; use App\Models\User; use App\Traits\Menu; use App\Models\Country; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class HomeController extends Controller { use Menu ; /***************** dashboard *****************/ public function dashboard() { $countryArray = $this->chartData(new Country); $cityArray = $this->chartData(new City); $activeUsers = User::where(['active' => true])->count() ; $notActiveUsers = User::where(['active' => false])->count() ; $stores_contracted = Store::where('has_contract' , 'true')->count(); $google_stores = Store::where('has_contract' , 'false')->count(); $active_companies =User::where('type' , 'company')->where('active' , true)->count(); $notActivecompanies =User::where('type' , 'company')->where('active' , false)->count(); $activeDelegate =User::where('type' , 'delegate')->where('active' , true)->count(); $notActiveDelegate =User::where('type' , 'delegate')->where('active' , false)->count(); $admins_active = Admin::where('blocked' , 0)->count(); $admins_blocked = Admin::where('blocked' , 1)->count(); $orders = Order::all()->count(); $active_orders = Order::where('status' , 'inprogress')->count(); $new_orders = Order::where('status' , 'open')->count(); $finished_orders = Order::where('status' , 'finished')->count(); $closed_orders = Order::where('status' , 'closed')->count(); // $menus = $this->home() ; // $introSiteCards = $this->introSiteCards() ; $colores = ['info' , 'danger' , 'warning' , 'success' , 'primary']; return view('admin.dashboard.index' , compact('colores' , 'activeUsers' ,'active_orders','orders', 'notActiveDelegate', 'finished_orders', 'closed_orders', 'activeDelegate','admins_blocked','admins_active','new_orders', 'stores_contracted' , 'google_stores' , 'active_companies' , 'notActivecompanies' , 'notActiveUsers' , 'countryArray' , 'cityArray')); } public function chartData($model) { $users = $model::select('id', 'created_at') ->get() ->groupBy(function($date) { return Carbon::parse($date->created_at)->format('m'); }); $usermcount = []; $userArr = []; foreach ($users as $key => $value) { $usermcount[(int)$key] = count($value); } for($i = 1; $i <= 12; $i++){ if(!empty($usermcount[$i])){ $userArr[] = $usermcount[$i]; }else{ $userArr[] = 0; } } return $userArr ; } }
Back to File Manager