Panen and include all support
This commit is contained in:
@@ -5,6 +5,8 @@ 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\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Panen extends Model
|
||||
@@ -18,11 +20,12 @@ class Panen extends Model
|
||||
* Atribut yang dapat diisi (mass assignable).
|
||||
*/
|
||||
protected $fillable = [
|
||||
'uid', // PN-1234567890-1234567890-1234567890 (lahan-tanaman-panen)
|
||||
// 'plant_id',
|
||||
'title',
|
||||
'land_id',
|
||||
'plant_id',
|
||||
'farmer_id',
|
||||
'commodity_name',
|
||||
'weight_kg',
|
||||
'land_description',
|
||||
'harvest_date',
|
||||
'notes',
|
||||
'sync_status',
|
||||
@@ -41,12 +44,25 @@ class Panen extends Model
|
||||
{
|
||||
return $this->belongsTo(Lahan::class, 'land_id');
|
||||
}
|
||||
public function tanaman(): BelongsTo
|
||||
public function detailKomoditas(): HasMany
|
||||
{
|
||||
return $this->belongsTo(Tanaman::class, 'plant_id');
|
||||
return $this->hasMany(PanenKomoditas::class, 'panen_id');
|
||||
}
|
||||
|
||||
public function tanamans(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Tanaman::class, 'panen_komoditas', 'panen_id', 'plant_id')
|
||||
->using(PanenKomoditas::class)
|
||||
->withPivot(['uid', 'commodity_name', 'weight_kg', 'sync_status'])
|
||||
->withTimestamps();
|
||||
}
|
||||
public function petani(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Profile::class, 'farmer_id');
|
||||
}
|
||||
|
||||
public function panenTanaman(): HasMany
|
||||
{
|
||||
return $this->hasMany(PanenTanaman::class, 'panen_id', 'id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user