1
0
Fork 0
internet-everythings-agricu.../app/Models/RegionPlantLog.php

37 lines
707 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Models;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
/**
* 种植记录
*/
class RegionPlantLog extends Model
{
use Filterable;
protected $appends = ['plant_state'];
protected $casts = [
'start_at' => 'datetime:Y-m-d',
'end_at' => 'datetime:Y-m-d',
];
//1进行中2已结束
protected function plantState():Attribute
{
return Attribute::make(
get: fn($value) => $this->end_at ? 2 : 1,
);
}
// 收获记录
public function harvestes()
{
return $this->hasMany(PlantHarvestLog::class, 'plant_id');
}
}