main
Ilham Wara Nugroho 2026-07-16 10:38:40 +07:00
parent 89167a425e
commit 28b0eb6b0f
1 changed files with 22 additions and 0 deletions

View File

@ -13,6 +13,28 @@ class Kuesioner extends Model
protected $primaryKey = 'KuesionerId';
protected $guarded = [];
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');