Merge branch 'main' of https://git.probindo.com/Probindo/database-pertani-web
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user