Merge branch 'main' of https://git.probindo.com/Probindo/database-pertani-web
This commit is contained in:
@@ -20,6 +20,7 @@ class Program extends Model
|
||||
"sub_domain",
|
||||
"tahun",
|
||||
"instansi",
|
||||
"nama_singkat",
|
||||
];
|
||||
|
||||
public function komoditas(): HasMany
|
||||
|
||||
@@ -0,0 +1,383 @@
|
||||
<?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 Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Models\Ekosistem\TabelBasisData;
|
||||
use App\Enums\LayoutForm;
|
||||
|
||||
class FormBasisData extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'ekosistem_basis_data_form';
|
||||
|
||||
protected $fillable = [
|
||||
'tabel_id',
|
||||
'parent_id',
|
||||
'tipe',
|
||||
'column_width',
|
||||
'kolom_id',
|
||||
'section_label',
|
||||
'urutan',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tipe' => LayoutForm::class
|
||||
];
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
public function form(): HasMany
|
||||
{
|
||||
return $this->hasMany(FormBasisData::class, 'parent_id')
|
||||
->with('form')
|
||||
->orderBy('urutan');
|
||||
}
|
||||
|
||||
public function kolom(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(KolomBasisData::class, 'kolom_id');
|
||||
}
|
||||
|
||||
public function renderHtml(string $state, $errors = null, $optionsFK = null, $values = null, $framework = 'bootstrap'): string
|
||||
{
|
||||
if ($framework == 'tailwind') {
|
||||
return match ($this->tipe) {
|
||||
LayoutForm::COLUMN => '<div className="space-y-2 form-control-validation">'
|
||||
.$this->childHtml($state, $errors, $optionsFK, $values, $framework).'</div>',
|
||||
LayoutForm::VALUE => $this->value($state, $errors, $optionsFK, $values, $framework),
|
||||
LayoutForm::SECTION => '<h3 className="font-semibold text-lg text-slate-900">'.$this->section_label.'</h3>',
|
||||
LayoutForm::ROW => '<div className="grid grid-cols-1 gap-5">'.$this->childHtml($state, $errors, $optionsFK, $values, $framework).'</div>',
|
||||
LayoutForm::HR_LINE => '<hr/>',
|
||||
default => ''
|
||||
};
|
||||
} else {
|
||||
return match ($this->tipe) {
|
||||
LayoutForm::COLUMN => '<div class="col-'.($this->column_width ?? 3).' mb-4 form-control-validation">'
|
||||
.$this->childHtml($state, $errors, $optionsFK, $values, $framework).'</div>',
|
||||
LayoutForm::VALUE => $this->value($state, $errors, $optionsFK, $values, $framework),
|
||||
LayoutForm::SECTION => '<h6 class="mb-3">'.$this->section_label.'</h6>',
|
||||
LayoutForm::ROW => '<div class="row">'.$this->childHtml($state, $errors, $optionsFK, $values, $framework).'</div>',
|
||||
LayoutForm::HR_LINE => '<hr/>',
|
||||
default => ''
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function childHtml(string $state, $errors = null, $optionsFK = null, $values = null, $framework = 'bootstrap'): string
|
||||
{
|
||||
$html = '';
|
||||
foreach ($this->form as $form) {
|
||||
$html .= $form->renderHtml($state, $errors, $optionsFK, $values, $framework);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function value(string $state, $errors = null, $optionsFK = null, $values = null, $framework = 'bootstrap'): string
|
||||
{
|
||||
$html = '';
|
||||
if ($this->kolom) {
|
||||
$k = $this->kolom;
|
||||
|
||||
$value = $values ? $values->where('kolom_id', $k->id)->first() : null;
|
||||
$oldValue = old($k->kolom);
|
||||
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Label htmlFor="label" className="text-sm font-medium text-slate-700">kolom_required'.$this->kolom->label;
|
||||
$html .= '</Label>';
|
||||
} else {
|
||||
$html .= '<label class="form-label" for="value-data-kolom_name">kolom_required'.$this->kolom->label;
|
||||
$html .= '</label>';
|
||||
}
|
||||
|
||||
if($k->tipe == 'varchar') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'text') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Textarea className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name">kolom_value</Textarea>';
|
||||
} else {
|
||||
$html .= '<textarea class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name">kolom_value</textarea>';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'integer') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="number" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" step="1" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="number" class="form-control" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" step="1" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'float') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" step="any" />';
|
||||
} else {
|
||||
$html .= '<input type="number" class="form-control kolom_error" id="add-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" step="any" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'date') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="date" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="date" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'datetime'){
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="datetime-local" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="datetime-local" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'boolean') {
|
||||
if ($state == 'preview' || $state == 'view') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="text" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
} elseif ($state == 'add') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="rounded-xl">
|
||||
<SelectItem value="1" className="rounded-lg">Ya</SelectItem>
|
||||
<SelectItem value="0" className="rounded-lg">Tidak</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error" id="value-data-kolom_name" name="kolom_name">
|
||||
<option value="1" '. (old($k->kolom) == 1 ? 'selected' : '') .'>Ya</option>
|
||||
<option value="0" '. (old($k->kolom) == 0 ? 'selected' : '') .'>Tidak</option>
|
||||
</select>';
|
||||
}
|
||||
} elseif ($state == 'edit') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="rounded-xl">
|
||||
<SelectItem value="1" className="rounded-lg">Ya</SelectItem>
|
||||
<SelectItem value="0" className="rounded-lg">Tidak</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error" id="value-data-kolom_name" name="kolom_name">
|
||||
<option value="1" '. ((old($k->kolom) ?? (($value ? $value['value_'.$k->tipe] : null) ?? null) == 1) ? 'selected' : '') .'>Ya</option>
|
||||
<option value="0" '. ((old($k->kolom) ?? (($value ? $value['value_'.$k->tipe] : null) ?? null) == 0) ? 'selected' : '') .'>Tidak</option>
|
||||
</select>';
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'foreign_key') {
|
||||
if ($state == 'preview' || $state == 'view') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="text" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
} elseif ($state == 'add') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value" id="value-data-kolom_name" name="kolom_name" className="form-select tipe-foreign_key kolom_error">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<SelectContent className="rounded-xl">
|
||||
<SelectItem value="'.$option->value.'" className="rounded-lg">'.$option->label.'</SelectItem>
|
||||
</SelectContent>';
|
||||
}
|
||||
}
|
||||
$html .= '</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-foreign_key kolom_error" id="value-data-kolom_name" name="kolom_name">';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<option value="'.$option->value.'" '.(old($k->kolom) == $option->value ? 'selected' : '').'>'.$option->label.'</option>';
|
||||
}
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
} elseif ($state == 'edit') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value" id="value-data-kolom_name" name="kolom_name" className="form-select tipe-foreign_key kolom_error">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<SelectContent className="rounded-xl">
|
||||
<SelectItem value="'.$option->value.'" className="rounded-lg" '.(old($k->kolom) ?? ($value ? ($value['value_relasi'] == $option->value) : null) ? 'selected' : '') .'>'.$option->label.'</SelectItem>
|
||||
</SelectContent>';
|
||||
}
|
||||
}
|
||||
$html .= '</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-foreign_key kolom_error" id="value-data-kolom_name" name="kolom_name">';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<option value="'.$option->value.'" '.(old($k->kolom) ?? ($value ? $value['value_relasi'] : null) == $option->value ? 'selected' : '').'>'.$option->label.'</option>';
|
||||
}
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'enum') {
|
||||
if ($state == 'preview' || $state == 'view') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="text" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
} elseif ($state == 'add') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value" id="value-data-kolom_name" name="kolom_name" className="form-select tipe-enum kolom_error">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<SelectContent className="rounded-xl">
|
||||
<SelectItem value="'.$opsi['value'].'" className="rounded-lg">'.$opsi['label'].'</SelectItem>
|
||||
</SelectContent>';
|
||||
}
|
||||
$html .= '</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-enum kolom_error" id="value-data-kolom_name" name="kolom_name">';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<option value="' .$opsi['value']. '" ' .(old($k->kolom) == $opsi['value'] ? 'selected' : ''). '>' .$opsi['label']. '</option>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
} elseif ($state == 'edit') {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value" id="value-data-kolom_name" name="kolom_name" className="form-select tipe-enum kolom_error">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<SelectContent className="rounded-xl">
|
||||
<SelectItem value="'.$opsi['value'].'" className="rounded-lg">'.$opsi['label'].'</SelectItem>
|
||||
</SelectContent>';
|
||||
}
|
||||
$html .= '</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-enum kolom_error" id="value-data-kolom_name" name="kolom_name">';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<option value="' .$opsi['value']. '" ' .(old($k->kolom) ?? ($value ? $value['value_'.$k->tipe] : null) == $opsi['value'] ? 'selected' : ''). '>' .$opsi['label']. '</option>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="text" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
|
||||
$errorClass = $errors && $errors->has($k->kolom)
|
||||
? 'is-invalid'
|
||||
: '';
|
||||
|
||||
if ($state == 'preview') {
|
||||
$html = Str::of($html)
|
||||
->replace('kolom_value', '')
|
||||
->replace('kolom_name', $k->kolom)
|
||||
->replace('kolom_error', '')
|
||||
->replace('kolom_required', '');
|
||||
} elseif ($state == 'add') {
|
||||
$html = Str::of($html)
|
||||
->replace('kolom_value', e($oldValue))
|
||||
->replace('kolom_name', $k->kolom)
|
||||
->replace('kolom_error', $errorClass)
|
||||
->replace('kolom_required', '')
|
||||
->replace('readonly', '');
|
||||
} elseif ($state == 'edit') {
|
||||
$html = Str::of($html)
|
||||
->replace('kolom_value', e($oldValue ?? ($value ? ($value['value_'.$k->tipe]) : null)))
|
||||
->replace('kolom_name', $k->kolom)
|
||||
->replace('kolom_error', $errorClass)
|
||||
->replace('kolom_required', '')
|
||||
->replace('readonly', '');
|
||||
} elseif ($state == 'view') {
|
||||
$html = Str::of($html)
|
||||
->replace('kolom_name', $k->kolom)
|
||||
->replace('kolom_error', '')
|
||||
->replace('kolom_required', '');
|
||||
|
||||
if ($k->tipe == 'boolean') {
|
||||
$html = Str::of($html)
|
||||
->replace('kolom_value', e($value ? ($value['value_'.$k->tipe] == 1 ? 'Ya' : 'Tidak') : null));
|
||||
} elseif($k->tipe == 'foreign_key') {
|
||||
$html = Str::of($html)
|
||||
->replace('kolom_value', e($value ? $value['value_relasi_label'] : null));
|
||||
} elseif($k->tipe == 'enum') {
|
||||
$html = Str::of($html)
|
||||
->replace('kolom_value', e($value ? $value['value_enum_label'] : null));
|
||||
} else {
|
||||
$html = Str::of($html)
|
||||
->replace('kolom_value', e($value ? $value['value_'.$k->tipe] : null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,14 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
use App\Models\Ekosistem\KolomBasisData;
|
||||
use App\Models\Ekosistem\GroupBasisData;
|
||||
use App\Models\Ekosistem\RingkasanBasisData;
|
||||
use App\Models\Ekosistem\FormBasisData;
|
||||
|
||||
class TabelBasisData extends Model
|
||||
{
|
||||
@@ -53,4 +57,20 @@ class TabelBasisData extends Model
|
||||
{
|
||||
return $this->hasMany(RingkasanBasisData::class, 'tabel_id')->orderBy('urutan');
|
||||
}
|
||||
|
||||
public function form(): HasMany
|
||||
{
|
||||
return $this->hasMany(FormBasisData::class, 'tabel_id')
|
||||
->whereNull('parent_id')
|
||||
->orderBy('urutan');
|
||||
}
|
||||
|
||||
public function renderHtml(string $state, $errors = null, $optionsFK = null, $values = null): string
|
||||
{
|
||||
$html = '';
|
||||
foreach ($this->form as $form) {
|
||||
$html .= $form->renderHtml($state, $errors, $optionsFK, $values);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class Lahan extends Model
|
||||
'status_kepemilikan',
|
||||
'profile_id',
|
||||
'desa_kelurahan_id',
|
||||
'uid',
|
||||
'path',
|
||||
'luas_lahan',
|
||||
'created_by',
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Master;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\Pertanian\Komoditas;
|
||||
|
||||
class JenisKomoditas extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $table = 'jenis_komoditas';
|
||||
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'komoditas_id',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function komoditas()
|
||||
{
|
||||
return $this->belongsTo(Komoditas::class, 'komoditas_id');
|
||||
}
|
||||
|
||||
public function varietas()
|
||||
{
|
||||
return $this->hasMany(Varietas::class, 'jenis_komoditas_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Master;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\Pertanian\Komoditas;
|
||||
use App\Models\Master\JenisKomoditas;
|
||||
|
||||
class Varietas extends Model
|
||||
{
|
||||
protected $table = 'master_varietas';
|
||||
|
||||
protected $fillable = [
|
||||
'komoditas_id',
|
||||
'jenis_komoditas_id',
|
||||
'nama',
|
||||
'deskripsi',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
public function jenisKomoditas()
|
||||
{
|
||||
return $this->belongsTo(JenisKomoditas::class, 'jenis_komoditas_id');
|
||||
}
|
||||
|
||||
public function komoditas()
|
||||
{
|
||||
return $this->belongsTo(Komoditas::class, 'komoditas_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Pertanian;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class JenisKomoditas extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
/**
|
||||
* Nama tabel yang terkait dengan model ini.
|
||||
* Un-comment baris di bawah jika nama tabel di database tidak jamak (plural).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'jenis_komoditas';
|
||||
|
||||
/**
|
||||
* Atribut yang dapat diisi secara massal (mass assignable).
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'kode',
|
||||
'keterangan',
|
||||
];
|
||||
|
||||
/**
|
||||
* Atribut yang harus dikonversi ke tipe data lain (casting).
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke model Komoditas atau Tanaman (jika ada).
|
||||
* Contoh: Satu Jenis Komoditas memiliki banyak data Tanaman/Komoditas turunannya.
|
||||
*/
|
||||
public function tanaman(): HasMany
|
||||
{
|
||||
return $this->hasMany(Tanaman::class, 'jenis_komoditas_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace App\Models\Pertanian;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Master\JenisKomoditas;
|
||||
use App\Models\Master\Varietas;
|
||||
|
||||
class Komoditas extends Model
|
||||
{
|
||||
@@ -30,4 +32,14 @@ class Komoditas extends Model
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ class Lahan extends Model
|
||||
protected $table = 'map_lahan';
|
||||
|
||||
protected $fillable = [
|
||||
'uid',
|
||||
'nama',
|
||||
'status_kepemilikan',
|
||||
'profile_id',
|
||||
@@ -37,22 +38,22 @@ class Lahan extends Model
|
||||
'path' => 'array',
|
||||
];
|
||||
|
||||
public function profile()
|
||||
public function profile(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Profile::class, 'profile_id');
|
||||
}
|
||||
|
||||
public function desaKelurahan()
|
||||
public function desaKelurahan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DesaKelurahan::class, 'desa_kelurahan_id');
|
||||
}
|
||||
|
||||
public function adat()
|
||||
public function adat(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Adat::class, 'adat_pemilik_id');
|
||||
}
|
||||
|
||||
public function tanaman()
|
||||
public function tanaman(): HasMany
|
||||
{
|
||||
return $this->hasMany(Tanaman::class, 'lahan_id');
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ namespace App\Models\Pertanian;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\Pertanian\Komoditas;
|
||||
use App\Models\Pertanian\Lahan;
|
||||
use App\Models\Profile;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
use App\Models\Pertanian\Lahan;
|
||||
use App\Models\Pertanian\Komoditas;
|
||||
use App\Models\Master\JenisKomoditas;
|
||||
use App\Models\Master\Varietas;
|
||||
|
||||
class Tanaman extends Model
|
||||
{
|
||||
@@ -18,13 +17,18 @@ class Tanaman extends Model
|
||||
protected $table = 'map_tanaman';
|
||||
|
||||
protected $fillable = [
|
||||
'uid',
|
||||
'nama',
|
||||
'jenis_komoditas_id',
|
||||
'varietas_id',
|
||||
'komoditas_id',
|
||||
'profile_id',
|
||||
'lahan_id',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'kondisi_tanaman',
|
||||
'metode_pengumpulan',
|
||||
'deskripsi',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
@@ -35,6 +39,16 @@ class Tanaman extends Model
|
||||
return $this->belongsTo(Komoditas::class, 'komoditas_id');
|
||||
}
|
||||
|
||||
public function jenisKomoditas()
|
||||
{
|
||||
return $this->belongsTo(JenisKomoditas::class, 'jenis_komoditas_id');
|
||||
}
|
||||
|
||||
public function varietas()
|
||||
{
|
||||
return $this->belongsTo(Varietas::class, 'varietas_id');
|
||||
}
|
||||
|
||||
public function profile()
|
||||
{
|
||||
return $this->belongsTo(Profile::class, 'profile_id');
|
||||
|
||||
@@ -4,11 +4,9 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Pertanian\Lahan;
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Profile extends Model
|
||||
{
|
||||
@@ -17,13 +15,14 @@ class Profile extends Model
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'role',
|
||||
'user_uid',
|
||||
'nama',
|
||||
'email',
|
||||
'telepon',
|
||||
'alamat',
|
||||
'kk',
|
||||
'ktp',
|
||||
|
||||
'uid',
|
||||
'desa_kelurahan_id',
|
||||
'path_kk',
|
||||
'file_kk',
|
||||
@@ -44,9 +43,4 @@ class Profile extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function lahan(): HasMany
|
||||
{
|
||||
return $this->hasMany(Lahan::class, 'profile_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ class Aktivitas extends Model
|
||||
"indikator",
|
||||
"deskripsi",
|
||||
"transformasi_id",
|
||||
"parent_id",
|
||||
"created_by",
|
||||
"updated_by"
|
||||
];
|
||||
|
||||
public function transformasi(): BelongsTo
|
||||
@@ -32,6 +35,20 @@ class Aktivitas extends Model
|
||||
|
||||
public function target(): HasMany
|
||||
{
|
||||
return $this->hasMany(Target::class, 'aktivitas_id', 'id');
|
||||
return $this->hasMany(Target::class, 'aktivitas_id', 'id')
|
||||
->orderBy('id', 'asc');
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Aktivitas::class, 'parent_id', 'id');
|
||||
}
|
||||
|
||||
public function aktivitas(): HasMany
|
||||
{
|
||||
return $this->hasMany(Aktivitas::class, 'parent_id', 'id')
|
||||
->where('jenis_aktivitas', 'aktivitas')
|
||||
->orderBy('kode', 'asc')
|
||||
->orderBy('id', 'asc');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ class Framework extends Model
|
||||
"nama",
|
||||
"tahun",
|
||||
"program_id",
|
||||
"created_by",
|
||||
"updated_by",
|
||||
];
|
||||
|
||||
public function program(): BelongsTo
|
||||
@@ -29,6 +31,8 @@ class Framework extends Model
|
||||
|
||||
public function transformasi(): HasMany
|
||||
{
|
||||
return $this->hasMany(Transformasi::class, 'framework_id', 'id');
|
||||
return $this->hasMany(Transformasi::class, 'framework_id', 'id')
|
||||
->orderBy('kode', 'asc')
|
||||
->orderBy('id', 'asc');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Program;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use App\Models\Program\Target;
|
||||
|
||||
class Realisasi extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'program_realisasi';
|
||||
|
||||
protected $fillable = [
|
||||
"target_id",
|
||||
"realisasi_integer",
|
||||
"realisasi_float",
|
||||
"realisasi_boolean",
|
||||
"created_by",
|
||||
"updated_by",
|
||||
"deleted_by",
|
||||
];
|
||||
|
||||
public function target(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Target::class, 'target_id', 'id');
|
||||
}
|
||||
|
||||
public function verifikasi(): HasMany
|
||||
{
|
||||
return $this->hasMany(Verifikasi::class, 'realisasi_id', 'id')->oldest();
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace App\Models\Program;
|
||||
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\Relations\HasOne;
|
||||
|
||||
use App\Models\Program\Aktivitas;
|
||||
|
||||
@@ -27,10 +29,25 @@ class Target extends Model
|
||||
"realisasi_float",
|
||||
"realisasi_boolean",
|
||||
"aktivitas_id",
|
||||
"tipe_realisasi",
|
||||
"value_query",
|
||||
"created_by",
|
||||
"updated_by",
|
||||
"deleted_by",
|
||||
];
|
||||
|
||||
public function aktivitas(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Aktivitas::class, 'aktivitas_id', 'id');
|
||||
}
|
||||
|
||||
public function realisasi(): HasMany
|
||||
{
|
||||
return $this->hasMany(Realisasi::class, 'target_id', 'id')->latest();
|
||||
}
|
||||
|
||||
public function latestRealisasi(): HasOne
|
||||
{
|
||||
return $this->hasOne(Realisasi::class, 'target_id', 'id')->latest();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,12 @@ class Transformasi extends Model
|
||||
return $this->belongsTo(Framework::class, 'framework_id', 'id');
|
||||
}
|
||||
|
||||
public function aktivitas(): HasMany
|
||||
public function tujuan(): HasMany
|
||||
{
|
||||
return $this->hasMany(Aktivitas::class, 'transformasi_id', 'id');
|
||||
return $this->hasMany(Aktivitas::class, 'transformasi_id', 'id')
|
||||
->whereNull('parent_id')
|
||||
->where('jenis_aktivitas', 'tujuan')
|
||||
->orderBy('kode', 'asc')
|
||||
->orderBy('id', 'asc');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Program;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
use App\Models\Program\Realisasi;
|
||||
|
||||
class Verifikasi extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'program_verifikasi';
|
||||
|
||||
protected $fillable = [
|
||||
"realisasi_id",
|
||||
"dokumen",
|
||||
"link_dokumen",
|
||||
"created_by",
|
||||
"updated_by",
|
||||
"deleted_by",
|
||||
];
|
||||
|
||||
public function realisasi(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Realisasi::class, 'realisasi_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ class User extends Authenticatable
|
||||
'password',
|
||||
'email_verified_at',
|
||||
'role',
|
||||
'username',
|
||||
'uid'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\wilayah;
|
||||
namespace App\Models\Wilayah;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
Reference in New Issue
Block a user