32 lines
679 B
PHP
32 lines
679 B
PHP
<?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, $attributes) => $attributes['end_at'] ? 2:1,
|
||
);
|
||
}
|
||
|
||
public function harvestes(){
|
||
return $this->hasMany(PlantHarvestLog::class, 'plant_id');
|
||
}
|
||
}
|