| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Module\Farm\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * 作物信息模型
- *
- * field start
- * @property int $id 主键ID
- * @property int $land_id 土地ID
- * @property int $user_id 用户ID
- * @property int $seed_id 种子ID
- * @property string $plant_time 种植时间
- * @property int $growth_stage 生长阶段:1种子期,2发芽期,3生长期,4成熟期,5枯萎期
- * @property string $stage_end_time 当前阶段结束时间
- * @property object|array $disasters 灾害情况
- * @property int $fertilized 当前阶段是否已使用化肥
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class FarmCrop extends Model
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'farm_crops';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- protected $fillable = [
- 'land_id',
- 'user_id',
- 'seed_id',
- 'plant_time',
- 'growth_stage',
- 'stage_end_time',
- 'disasters',
- 'fertilized',
- ];
- /**
- * 应该被转换为日期的属性
- *
- * @var array
- */
- protected $dates = [
- 'plant_time',
- 'stage_end_time',
- 'created_at',
- 'updated_at',
- ];
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'disasters' => 'json',
- 'fertilized' => 'boolean',
- ];
- /**
- * 获取关联的土地
- *
- * @return BelongsTo
- */
- public function land(): BelongsTo
- {
- return $this->belongsTo(FarmLand::class, 'land_id', 'id');
- }
- /**
- * 获取关联的种子
- *
- * @return BelongsTo
- */
- public function seed(): BelongsTo
- {
- return $this->belongsTo(FarmSeed::class, 'seed_id', 'id');
- }
- }
|