TaskCategory.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Module\Task\Models;
  3. use UCore\ModelCore;
  4. use Illuminate\Database\Eloquent\Relations\HasMany;
  5. /**
  6. * 任务分类模型
  7. *
  8. * field start
  9. * @property int $id 主键
  10. * @property string $name 分类名称
  11. * @property string $code 分类编码(唯一)
  12. * @property string $description 分类描述
  13. * @property int $sort_order 排序顺序
  14. * @property \Carbon\Carbon $created_at 创建时间
  15. * @property \Carbon\Carbon $updated_at 更新时间
  16. * field end
  17. */
  18. class TaskCategory extends ModelCore
  19. {
  20. /**
  21. * 与模型关联的表名
  22. * 注意:由于数据库配置中有kku_前缀,但实际表名是task_categories,所以需要覆盖前缀
  23. *
  24. * @var string
  25. */
  26. protected $table = 'task_categories';
  27. /**
  28. * 获取表名(覆盖父类方法以禁用前缀)
  29. *
  30. * @return string
  31. */
  32. public function getTable()
  33. {
  34. return $this->table;
  35. }
  36. /**
  37. * 主键
  38. *
  39. * @var string
  40. */
  41. protected $primaryKey = 'id';
  42. // attrlist start
  43. protected $fillable = [
  44. 'id',
  45. 'name',
  46. 'code',
  47. 'description',
  48. 'sort_order',
  49. ];
  50. // attrlist end
  51. /**
  52. * 获取该分类下的所有任务
  53. *
  54. * @return HasMany
  55. */
  56. public function tasks(): HasMany
  57. {
  58. return $this->hasMany(Task::class, 'category_id', 'id');
  59. }
  60. }