Category.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Models\Goods;
  3. use App\Base\BaseModel;
  4. use Faker\Provider\Image;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. /**
  7. * App\Models\Goods\Category
  8. *
  9. * @property int $id
  10. * @property string $name
  11. * @property string $thumb
  12. * @property int $level 层级
  13. * @property int $parent_id 上级分类ID
  14. * @property int $weight 权重
  15. * @property int $index_weight 推荐位权重
  16. * @property int $category_weight 推荐位权重
  17. * @property int $search_weight 搜索页权重
  18. * @property \Illuminate\Support\Carbon|null $created_at
  19. * @property \Illuminate\Support\Carbon|null $updated_at
  20. * @property \Illuminate\Support\Carbon|null $deleted_at
  21. * @method static \Illuminate\Database\Eloquent\Builder|Category newModelQuery()
  22. * @method static \Illuminate\Database\Eloquent\Builder|Category newQuery()
  23. * @method static \Illuminate\Database\Query\Builder|Category onlyTrashed()
  24. * @method static \Illuminate\Database\Eloquent\Builder|Category query()
  25. * @method static \Illuminate\Database\Eloquent\Builder|Category whereCategoryWeight($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|Category whereCreatedAt($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|Category whereDeletedAt($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder|Category whereId($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder|Category whereIndexWeight($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder|Category whereLevel($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder|Category whereName($value)
  32. * @method static \Illuminate\Database\Eloquent\Builder|Category whereParentId($value)
  33. * @method static \Illuminate\Database\Eloquent\Builder|Category whereSearchWeight($value)
  34. * @method static \Illuminate\Database\Eloquent\Builder|Category whereThumb($value)
  35. * @method static \Illuminate\Database\Eloquent\Builder|Category whereUpdatedAt($value)
  36. * @method static \Illuminate\Database\Eloquent\Builder|Category whereWeight($value)
  37. * @method static \Illuminate\Database\Query\Builder|Category withTrashed()
  38. * @method static \Illuminate\Database\Query\Builder|Category withoutTrashed()
  39. * @mixin \Eloquent
  40. * @property-read Category|null $parent
  41. */
  42. class Category extends BaseModel
  43. {
  44. use SoftDeletes;
  45. protected $table = "category";
  46. public function format(...$options)
  47. {
  48. $return = [
  49. "id" => $this->id,
  50. "name" => $this->name,
  51. "thumb" => $this->thumb,
  52. "level" => $this->level,
  53. "parent_id" => optional($this->parent)->id ?? 0,
  54. "parent_name" => optional($this->parent)->name ?? 0,
  55. "weight" => $this->weight,
  56. "index_weight" => $this->index_weight,
  57. "category_weight" => $this->category_weight,
  58. "search_weight" => $this->search_weight,
  59. ];
  60. return $return;
  61. }
  62. public function parent()
  63. {
  64. return $this->belongsTo(Category::class, "parent_id");
  65. }
  66. }