ItemRecipeMaterial.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Module\GameItems\Models;
  3. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  4. use UCore\ModelCore;
  5. /**
  6. * 合成配方材料
  7. *
  8. * field start
  9. * @property int $id 记录ID,主键
  10. * @property int $recipe_id 配方ID,外键关联kku_item_recipes表
  11. * @property int $item_id 材料物品ID,外键关联kku_item_items表
  12. * @property int $quantity 所需数量
  13. * @property int $is_consumed 是否消耗(0:不消耗, 1:消耗)
  14. * @property \Carbon\Carbon $created_at 创建时间
  15. * @property \Carbon\Carbon $updated_at 更新时间
  16. * field end
  17. */
  18. class ItemRecipeMaterial extends ModelCore
  19. {
  20. /**
  21. * 与模型关联的表名
  22. *
  23. * @var string
  24. */
  25. protected $table = 'item_recipe_materials';
  26. // attrlist start
  27. protected $fillable = [
  28. 'id',
  29. 'recipe_id',
  30. 'item_id',
  31. 'quantity',
  32. 'is_consumed',
  33. ];
  34. // attrlist end
  35. /**
  36. * 应该被转换为原生类型的属性
  37. *
  38. * @var array
  39. */
  40. protected $casts = [
  41. 'quantity' => 'integer',
  42. 'is_consumed' => 'boolean',
  43. ];
  44. /**
  45. * 获取关联的配方
  46. *
  47. * @return BelongsTo
  48. */
  49. public function recipe(): BelongsTo
  50. {
  51. return $this->belongsTo(ItemRecipe::class, 'recipe_id');
  52. }
  53. /**
  54. * 获取关联的物品
  55. *
  56. * @return BelongsTo
  57. */
  58. public function item(): BelongsTo
  59. {
  60. return $this->belongsTo(Item::class, 'item_id');
  61. }
  62. }