From ba5ed6a39e8d931403c2f70fb6c275119cf1168f Mon Sep 17 00:00:00 2001 From: andes2912 Date: Sun, 29 May 2022 22:41:00 +0700 Subject: [PATCH] Bug fix data statistik --- app/Http/Controllers/HomeController.php | 29 ++++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 2cf08b4..c129931 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -52,17 +52,34 @@ public function index() } // DASHBOARD MURID \\ elseif ($role == 'Murid') { + $auth = Auth::id(); $event = Events::where('is_active','0')->first(); - $lateness = Borrowing::with(['members' => function($q){ - $q->where('user_id', Auth::id()); - }]) + $lateness = Borrowing::with('members') + ->when(isset($auth), function($q) use($auth){ + $q->whereHas('members', function($a) use($auth){ + switch ($auth) { + case $auth: + $a->where('user_id', Auth::id()); + break; + } + }); + }) ->whereNull('lateness') ->count(); - $pinjam = Borrowing::with(['members' => function($q){ - $q->where('user_id', Auth::id()); - }])->count(); + + $pinjam = Borrowing::with('members') + ->when(isset($auth), function($q) use($auth){ + $q->whereHas('members', function($a) use($auth){ + switch ($auth) { + case $auth: + $a->where('user_id', Auth::id()); + break; + } + }); + }) + ->count(); return view('murid::index', compact('event','lateness','pinjam'));