FarmLand.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * field start
  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. * field end
  17. */
  18. class FarmLand extends Model
  19. {
  20. /**
  21. * 与模型关联的表名
  22. *
  23. * @var string
  24. */
  25. protected $table = 'farm_lands';
  26. /**
  27. * 可批量赋值的属性
  28. *
  29. * @var array
  30. */
  31. protected $fillable = [
  32. 'user_id',
  33. 'position',
  34. 'land_type',
  35. 'status',
  36. ];
  37. /**
  38. * 获取关联的用户农场
  39. *
  40. * @return BelongsTo
  41. */
  42. public function farmUser(): BelongsTo
  43. {
  44. return $this->belongsTo(FarmUser::class, 'user_id', 'user_id');
  45. }
  46. /**
  47. * 获取关联的土地类型
  48. *
  49. * @return BelongsTo
  50. */
  51. public function landType(): BelongsTo
  52. {
  53. return $this->belongsTo(FarmLandType::class, 'land_type', 'id');
  54. }
  55. /**
  56. * 获取关联的作物
  57. *
  58. * @return HasOne
  59. */
  60. public function crop(): HasOne
  61. {
  62. return $this->hasOne(FarmCrop::class, 'land_id', 'id');
  63. }
  64. }