main
Ilham Wara Nugroho 2026-07-16 10:44:50 +07:00
parent d9532d181f
commit aeb01614eb
1 changed files with 22 additions and 0 deletions

View File

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