FarmLand.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Module\Farm\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use Illuminate\Database\Eloquent\Relations\HasOne;
  6. /**
  7. * 土地信息模型
  8. *
  9. * @property int $id 主键ID
  10. * @property int $user_id 用户ID
  11. * @property int $position 土地位置(1-20)
  12. * @property int $land_type 土地类型:1普通,2红土,3黑土,4金,5蓝,6紫
  13. * @property int $status 土地状态:0空闲,1种植中,2灾害,3可收获,4枯萎
  14. * @property \Carbon\Carbon $created_at 创建时间
  15. * @property \Carbon\Carbon $updated_at 更新时间
  16. */
  17. class FarmLand extends Model
  18. {
  19. /**
  20. * 与模型关联的表名
  21. *
  22. * @var string
  23. */
  24. protected $table = 'farm_lands';
  25. /**
  26. * 可批量赋值的属性
  27. *
  28. * @var array
  29. */
  30. protected $fillable = [
  31. 'user_id',
  32. 'position',
  33. 'land_type',
  34. 'status',
  35. ];
  36. /**
  37. * 获取关联的用户农场
  38. *
  39. * @return BelongsTo
  40. */
  41. public function farmUser(): BelongsTo
  42. {
  43. return $this->belongsTo(FarmUser::class, 'user_id', 'user_id');
  44. }
  45. /**
  46. * 获取关联的土地类型
  47. *
  48. * @return BelongsTo
  49. */
  50. public function landType(): BelongsTo
  51. {
  52. return $this->belongsTo(FarmLandType::class, 'land_type', 'id');
  53. }
  54. /**
  55. * 获取关联的作物
  56. *
  57. * @return HasOne
  58. */
  59. public function crop(): HasOne
  60. {
  61. return $this->hasOne(FarmCrop::class, 'land_id', 'id');
  62. }
  63. }