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');