Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

DashboardController.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Apresiasi;
  4. use App\Models\Pelaporan;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7. class DashboardController extends Controller
  8. {
  9. // public function index(Request $request){
  10. // return view('/dashboard')->with('success','Success login');
  11. // }
  12. public function index(Request $request){
  13. $laporan = Pelaporan::with('tindakan','user')->get();
  14. $user = $request->user();
  15. if ($user->role == 'admin') {
  16. // Jika pengguna adalah admin, hitung total berdasarkan tindakan_id
  17. $laporan = Pelaporan::with('tindakan','user')->get();
  18. $total = Pelaporan::where('tindakan_id', 1)->count();
  19. $tot = Pelaporan::where('tindakan_id', 2)->count();
  20. $tots = Pelaporan::where('tindakan_id', 3)->count();
  21. $totals = Pelaporan::where('tindakan_id', 4)->count();
  22. } elseif ($user->role == 'user') {
  23. // Jika pengguna adalah pengguna biasa, hitung riwayat pelaporan milik pengguna tersebut
  24. $riwayatPelaporan = Pelaporan::where('user_id', $user->id)->get();
  25. $laporan = $riwayatPelaporan->with('tindakan','user')->count();
  26. // Menghitung total riwayat pelaporan yang dimiliki oleh pengguna
  27. $total = $riwayatPelaporan->where('tindakan_id', 1)->count();
  28. // Menghitung total berdasarkan tindakan_id dari riwayat pelaporan pengguna
  29. $tot = $riwayatPelaporan->where('tindakan_id', 2)->count();
  30. $tots = $riwayatPelaporan->where('tindakan_id', 3)->count();
  31. $totals = $riwayatPelaporan->where('tindakan_id', 4)->count();
  32. }
  33. $pelaporans = Pelaporan::all();
  34. $apresiasi = Apresiasi::all();
  35. return view('users.dashboard', compact('laporan','apresiasi','pelaporans','total', 'tot', 'tots', 'totals'));
  36. }
  37. }