| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Module\Farm\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- /**
- * 土地信息模型
- *
- * @property int $id 主键ID
- * @property int $user_id 用户ID
- * @property int $position 土地位置(1-20)
- * @property int $land_type 土地类型:1普通,2红土,3黑土,4金,5蓝,6紫
- * @property int $status 土地状态:0空闲,1种植中,2灾害,3可收获,4枯萎
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- */
- class FarmLand extends Model
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'farm_lands';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- protected $fillable = [
- 'user_id',
- 'position',
- 'land_type',
- 'status',
- ];
- /**
- * 获取关联的用户农场
- *
- * @return BelongsTo
- */
- public function farmUser(): BelongsTo
- {
- return $this->belongsTo(FarmUser::class, 'user_id', 'user_id');
- }
- /**
- * 获取关联的土地类型
- *
- * @return BelongsTo
- */
- public function landType(): BelongsTo
- {
- return $this->belongsTo(FarmLandType::class, 'land_type', 'id');
- }
- /**
- * 获取关联的作物
- *
- * @return HasOne
- */
- public function crop(): HasOne
- {
- return $this->hasOne(FarmCrop::class, 'land_id', 'id');
- }
- }
|