From aeb01614eb9651a35c467ae3dcdfe11caa725816 Mon Sep 17 00:00:00 2001 From: Ilham Wara Nugroho Date: Thu, 16 Jul 2026 10:44:50 +0700 Subject: [PATCH] update --- app/Models/SampahBelumTerkelola.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/Models/SampahBelumTerkelola.php b/app/Models/SampahBelumTerkelola.php index df56695..a88f88e 100644 --- a/app/Models/SampahBelumTerkelola.php +++ b/app/Models/SampahBelumTerkelola.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Builder; class SampahBelumTerkelola extends Model { @@ -13,6 +14,27 @@ class SampahBelumTerkelola extends Model protected $guarded = []; protected $primaryKey = 'SampahBelumTerkelolaId'; + protected static function booted() + { + static::addGlobalScope('filterSekolah', function (Builder $builder) { + + $role = session('group_alias'); // misal: dinas_pendidikan atau kemenag + + if ($role == 'dinas_pendidikan') { + + $builder->whereHas('sekolah', function ($q) { + $q->where('is_kemenag', false); + }); + + } elseif ($role == 'kemenag') { + + $builder->whereHas('sekolah', function ($q) { + $q->where('is_kemenag', true); + }); + } + }); + } + public function sekolah() { return $this->belongsTo(\App\Models\Master\Sekolah::class,'ms_sekolah_id','MsSekolahId');