59 lines
1.3 KiB
PHP
59 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Pertanian;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use App\Models\Master\JenisKomoditas;
|
|
use App\Models\Master\Varietas;
|
|
use App\Models\Pertanian\Petani;
|
|
|
|
class Komoditas extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'master_komoditas';
|
|
|
|
protected $casts = [
|
|
'is_utama' => 'boolean',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'nama',
|
|
'kode',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
'is_utama',
|
|
];
|
|
|
|
protected static function booted()
|
|
{
|
|
static::addGlobalScope('program', function (Builder $builder) {
|
|
|
|
if (!app()->has('SystemProgram')) {
|
|
return;
|
|
}
|
|
|
|
$builder->whereIn('id', app('SystemProgram')->komoditas()->pluck('id'));
|
|
});
|
|
}
|
|
|
|
public function jenisKomoditas()
|
|
{
|
|
return $this->hasMany(JenisKomoditas::class, 'komoditas_id');
|
|
}
|
|
|
|
public function varietas()
|
|
{
|
|
return $this->hasMany(Varietas::class, 'komoditas_id');
|
|
}
|
|
|
|
public function petani(): HasMany
|
|
{
|
|
return $this->hasMany(Petani::class, 'komoditas_id');
|
|
}
|
|
}
|