Files
database-pertani-web/app/Models/Ekosistem/RingkasanBasisData.php
T
2026-05-04 15:07:56 +07:00

47 lines
1.1 KiB
PHP

<?php
namespace App\Models\Ekosistem;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Ekosistem\TabelBasisData;
use App\Models\Core\Program;
class RingkasanBasisData extends Model
{
use SoftDeletes;
protected $table = 'ekosistem_basis_data_ringkasan';
protected $fillable = [
'tabel_id',
'heading',
'subheading',
'query_ringkasan',
'urutan',
'created_by',
'updated_by',
'deleted_by',
];
protected static function booted()
{
static::creating(function ($model) {
$max = self::where('tabel_id', $model->tabel_id)->max('urutan');
$model->urutan = ($max ?? 0) + 1;
});
static::addGlobalScope('order', function (Builder $builder) {
$builder->orderBy('urutan');
});
}
public function tabel(): BelongsTo
{
return $this->belongsTo(TabelBasisData::class, 'tabel_id');
}
}