sekolah_adiwiyata/app/Models/ProfileSekolah.php

48 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class ProfileSekolah extends Model
{
use HasFactory;
protected $table = 'profile';
protected $primaryKey = 'ProfileId';
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') || ($role == 'penilai_disdik')) {
$builder->whereHas('sekolah', function ($q) {
$q->where('is_kemenag', false);
});
} elseif (($role == 'kemenag') || ($role == 'penilai_kemenag')) {
$builder->whereHas('sekolah', function ($q) {
$q->where('is_kemenag', true);
});
}
});
}
public function tingkat()
{
return $this->belongsTo(\App\Models\Master\MasterTingkatSekolah::class,'ms_tingkat_sekolah_id','MsTingkatSekolahId');
}
public function sekolah()
{
return $this->belongsTo(\App\Models\Master\Sekolah::class,'ms_sekolah_id','MsSekolahId');
}
}