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

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