No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DashboardController.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Helpers\Helper;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\DB;
  6. //modal
  7. ;
  8. use Carbon\Carbon;
  9. use Illuminate\Support\Str;
  10. use Auth;
  11. //UTILS
  12. use App\Utils\DashboardUtil;
  13. //MODEL
  14. use App\User;
  15. class DashboardController extends Controller
  16. {
  17. /**
  18. * Title untuk judul di web
  19. * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
  20. */
  21. private $title = 'Admin';
  22. private $route = 'admin.dashboard.'; //path awal foldernya ajah
  23. protected $DashboardUtil;
  24. public function __construct(DashboardUtil $DashboardUtil)
  25. {
  26. $this->DashboardUtil = $DashboardUtil;
  27. DB::enableQueryLog();
  28. }
  29. public function index()
  30. {
  31. $reguler_points = User::select('users.name', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 0)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->limit(5)->get();
  32. $reguler_point_all = [];
  33. $reguler_user_all = [];
  34. foreach($reguler_points as $key => $value){
  35. array_push($reguler_point_all , intval($value->total_point));
  36. array_push($reguler_user_all , $value->name);
  37. }
  38. $event_points = User::select('users.name', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 1)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->limit(5)->get();
  39. $event_point_all = [];
  40. $event_user_all = [];
  41. foreach($event_points as $key => $value){
  42. array_push($event_point_all , intval($value->total_point));
  43. array_push($event_user_all , $value->name);
  44. }
  45. $data = [
  46. //bawaan
  47. 'title' => $this->title,
  48. 'route' => $this->route,
  49. 'reguler_user_all' => $reguler_user_all,
  50. 'reguler_point_all' => $reguler_point_all,
  51. 'event_user_all' => $event_user_all,
  52. 'event_point_all' => $event_point_all,
  53. ];
  54. // dd($data['log_points']);
  55. return view($this->route . 'index', $data);
  56. }
  57. }