FarmCrop.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Module\Farm\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. /**
  6. * 作物信息模型
  7. *
  8. * field start
  9. * @property int $id 主键ID
  10. * @property int $land_id 土地ID
  11. * @property int $user_id 用户ID
  12. * @property int $seed_id 种子ID
  13. * @property string $plant_time 种植时间
  14. * @property int $growth_stage 生长阶段:1种子期,2发芽期,3生长期,4成熟期,5枯萎期
  15. * @property string $stage_end_time 当前阶段结束时间
  16. * @property object|array $disasters 灾害情况
  17. * @property int $fertilized 当前阶段是否已使用化肥
  18. * @property \Carbon\Carbon $created_at 创建时间
  19. * @property \Carbon\Carbon $updated_at 更新时间
  20. * field end
  21. */
  22. class FarmCrop extends Model
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'farm_crops';
  30. /**
  31. * 可批量赋值的属性
  32. *
  33. * @var array
  34. */
  35. protected $fillable = [
  36. 'land_id',
  37. 'user_id',
  38. 'seed_id',
  39. 'plant_time',
  40. 'growth_stage',
  41. 'stage_end_time',
  42. 'disasters',
  43. 'fertilized',
  44. ];
  45. /**
  46. * 应该被转换为日期的属性
  47. *
  48. * @var array
  49. */
  50. protected $dates = [
  51. 'plant_time',
  52. 'stage_end_time',
  53. 'created_at',
  54. 'updated_at',
  55. ];
  56. /**
  57. * 应该被转换为原生类型的属性
  58. *
  59. * @var array
  60. */
  61. protected $casts = [
  62. 'disasters' => 'json',
  63. 'fertilized' => 'boolean',
  64. ];
  65. /**
  66. * 获取关联的土地
  67. *
  68. * @return BelongsTo
  69. */
  70. public function land(): BelongsTo
  71. {
  72. return $this->belongsTo(FarmLand::class, 'land_id', 'id');
  73. }
  74. /**
  75. * 获取关联的种子
  76. *
  77. * @return BelongsTo
  78. */
  79. public function seed(): BelongsTo
  80. {
  81. return $this->belongsTo(FarmSeed::class, 'seed_id', 'id');
  82. }
  83. }