| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Module\Farm\Models;
- use App\Module\Farm\Enums\LAND_STATUS;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- /**
- * 土地信息模型
- * field start
- * @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 更新时间
- * field end
- * @property-read FarmUser $farmUser 关联的用户农场
- * @property-read FarmLandType $landType 关联的土地类型
- *
- * @package App\Module\Farm\Models
- */
- class FarmLand extends Model
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'farm_land_users';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- protected $fillable = [
- 'user_id',
- 'position',
- 'land_type',
- 'status',
- ];
- // 暂时移除枚举类型转换,避免在表单处理时出现类型问题
- protected $casts = [
- // 'status' => LAND_STATUS::class
- ];
- /**
- * 获取关联的用户农场
- *
- * @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');
- }
- }
|