56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Wilayah;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
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
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'master_provinsi';
|
|
|
|
protected $fillable = [
|
|
'kode',
|
|
'nama',
|
|
'path',
|
|
'iso',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
];
|
|
|
|
public function kabupatenKota()
|
|
{
|
|
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');
|
|
});
|
|
|
|
});
|
|
});
|
|
}
|
|
}
|