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