FarmLandUpgradeConfig.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * @property int $id 主键ID
  9. * @property int $from_type_id 起始土地类型ID
  10. * @property int $to_type_id 目标土地类型ID
  11. * @property array $materials 升级所需材料
  12. * @property array|null $conditions 其他升级条件
  13. * @property \Carbon\Carbon $created_at 创建时间
  14. * @property \Carbon\Carbon $updated_at 更新时间
  15. */
  16. class FarmLandUpgradeConfig extends Model
  17. {
  18. /**
  19. * 与模型关联的表名
  20. *
  21. * @var string
  22. */
  23. protected $table = 'farm_land_upgrade_configs';
  24. /**
  25. * 可批量赋值的属性
  26. *
  27. * @var array
  28. */
  29. protected $fillable = [
  30. 'from_type_id',
  31. 'to_type_id',
  32. 'materials',
  33. 'conditions',
  34. ];
  35. /**
  36. * 应该被转换为原生类型的属性
  37. *
  38. * @var array
  39. */
  40. protected $casts = [
  41. 'materials' => 'json',
  42. 'conditions' => 'json',
  43. ];
  44. /**
  45. * 获取起始土地类型
  46. *
  47. * @return BelongsTo
  48. */
  49. public function fromType(): BelongsTo
  50. {
  51. return $this->belongsTo(FarmLandType::class, 'from_type_id', 'id');
  52. }
  53. /**
  54. * 获取目标土地类型
  55. *
  56. * @return BelongsTo
  57. */
  58. public function toType(): BelongsTo
  59. {
  60. return $this->belongsTo(FarmLandType::class, 'to_type_id', 'id');
  61. }
  62. }