<?php
namespace App\Http\Controllers;
use App\Models\Dps;
use App\Models\Tps;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class DashboardController extends Controller
{
public function index()
{
$jumlahDps = Dps::query();
$jumlahTps = Tps::query();
$jumlahSaksi = User::where('role', 'saksi');
if(auth()->user()->role == "koordinator-kelurahan-desa"){
$jumlahDps = $jumlahDps->whereHas('tps',function($w){
$w->where('kelurahan_desa_id',auth()->user()->kelurahan_desa_id);
});
$jumlahDps = $jumlahDps->where('kelurahan_desa_id',auth()->user()->kelurahan_desa_id);
$jumlahSaksi = $jumlahSaksi->where('kelurahan_desa_id',auth()->user()->kelurahan_desa_id);
}
if(auth()->user()->role == "koordinator-kecamatan"){
$jumlahDps = $jumlahDps->whereHas('tps.kelurahan_desa',function($w){
$w->where('kecamatan_id',auth()->user()->kecamatan_id);
});
$jumlahTps = $jumlahTps->whereHas('kelurahan_desa',function($w){
$w->where('kecamatan_id',auth()->user()->kecamatan_id);
});
$jumlahSaksi = $jumlahSaksi->whereHas('kelurahan_desa',function($w){
$w->where('kecamatan_id',auth()->user()->kecamatan_id);
});
}
if(auth()->user()->role == "koordinator-kabupaten-kota"){
$jumlahDps = $jumlahDps->whereHas('tps.kelurahan_desa.kecamatan',function($w){
$w->where('kabupaten_kota_id',auth()->user()->kabupaten_kota_id);
});
$jumlahTps = $jumlahTps->whereHas('kelurahan_desa.kecamatan',function($w){
$w->where('kabupaten_kota_id',auth()->user()->kabupaten_kota_id);
});
$jumlahSaksi = $jumlahSaksi->whereHas('kelurahan_desa.kecamatan',function($w){
$w->where('kabupaten_kota_id',auth()->user()->kabupaten_kota_id);
});
}
$jumlahDps = $jumlahDps->count('id');
$jumlahTps = $jumlahTps->count('id');
$jumlahSaksi = $jumlahSaksi->count('id');
return view('dashboard', compact('jumlahDps', 'jumlahTps', 'jumlahSaksi'));
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]