68 lines
1.6 KiB
PHP
68 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Map;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Panen extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
// Nama tabel sesuai DDL sebelumnya
|
|
protected $table = 'map_panen';
|
|
|
|
/**
|
|
* Atribut yang dapat diisi (mass assignable).
|
|
*/
|
|
protected $fillable = [
|
|
'land_id',
|
|
'plant_id',
|
|
'farmer_id',
|
|
'commodity_name',
|
|
'weight_kg',
|
|
'harvest_date',
|
|
'notes',
|
|
'sync_status',
|
|
];
|
|
|
|
/**
|
|
* Casting tipe data agar konsisten saat diakses di Frontend/JSON.
|
|
*/
|
|
protected $casts = [
|
|
'weight_kg' => 'float',
|
|
'harvest_date' => 'date:Y-m-d',
|
|
'land_id' => 'integer',
|
|
'plant_id' => 'integer',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Relasi ke Lahan (Many-to-One)
|
|
*/
|
|
public function lahan(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Lahan::class, 'land_id');
|
|
}
|
|
|
|
/**
|
|
* Relasi ke Tanaman (Many-to-One)
|
|
*/
|
|
public function tanaman(): BelongsTo
|
|
{
|
|
// Pastikan nama model Tanaman sudah sesuai (misal: Tanaman atau Plant)
|
|
return $this->belongsTo(Tanaman::class, 'plant_id');
|
|
}
|
|
|
|
/**
|
|
* Relasi ke Profile Petani (Many-to-One)
|
|
*/
|
|
public function petani(): BelongsTo
|
|
{
|
|
// farmer_id merujuk ke tabel profiles (profile_id)
|
|
return $this->belongsTo(\App\Models\Profile::class, 'farmer_id');
|
|
}
|
|
} |