globalscope wilayah
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\Wilayah\KabupatenKota;
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class Provinsi extends Model
|
||||
{
|
||||
@@ -28,4 +29,27 @@ class Provinsi extends Model
|
||||
{
|
||||
return $this->hasMany(KabupatenKota::class, 'provinsi_id');
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::addGlobalScope('program', function (Builder $builder) {
|
||||
|
||||
if (!app()->has('SystemProgram')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$programId = app('SystemProgram')->id;
|
||||
|
||||
$builder->where(function ($query) use ($programId) {
|
||||
|
||||
$query->whereIn('id', function ($q) use ($programId) {
|
||||
$q->select('provinsi_id')
|
||||
->from('core_program_lokasi')
|
||||
->where('program_id', $programId)
|
||||
->whereNotNull('provinsi_id');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user