43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class SampahTerkelola extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'sampah_terkelola';
|
|
protected $guarded = [];
|
|
protected $primaryKey = 'SampahTerkelolaId';
|
|
|
|
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 sekolah()
|
|
{
|
|
return $this->belongsTo(\App\Models\Master\Sekolah::class,'ms_sekolah_id','MsSekolahId');
|
|
}
|
|
}
|