52 lines
1.2 KiB
PHP
52 lines
1.2 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\Builder;
|
|
|
|
use App\Models\Ekosistem\TabelBasisData;
|
|
|
|
class KolomBasisData extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'ekosistem_basis_data_kolom';
|
|
|
|
protected $fillable = [
|
|
'tabel_id',
|
|
'kolom',
|
|
'label',
|
|
'tipe',
|
|
'validasi',
|
|
'urutan',
|
|
'relasi_tabel',
|
|
'relasi_kolom_id',
|
|
'relasi_kolom_label',
|
|
'enum_opsi',
|
|
];
|
|
|
|
protected $casts = [
|
|
'validasi' => 'array',
|
|
'enum_opsi' => 'array',
|
|
];
|
|
|
|
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');
|
|
}
|
|
}
|