Просмотр файла app/Models/Board.php

Размер файла: 1.38Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Models;
  6.  
  7. use App\Traits\UploadTrait;
  8. use Illuminate\Database\Eloquent\Collection;
  9. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  10. use Illuminate\Database\Eloquent\Relations\HasMany;
  11.  
  12. /**
  13. * Class Board
  14. *
  15. * @property int id
  16. * @property int sort
  17. * @property int parent_id
  18. * @property string name
  19. * @property int count_items
  20. * @property int closed
  21. * @property Collection children
  22. * @property Board parent
  23. */
  24. class Board extends BaseModel
  25. {
  26. use UploadTrait;
  27.  
  28. /**
  29. * Indicates if the model should be timestamped.
  30. *
  31. * @var bool
  32. */
  33. public $timestamps = false;
  34.  
  35. /**
  36. * The attributes that aren't mass assignable.
  37. *
  38. * @var array
  39. */
  40. protected $guarded = [];
  41.  
  42. /**
  43. * Директория загрузки файлов
  44. *
  45. * @var string
  46. */
  47. public $uploadPath = UPLOADS . '/boards';
  48.  
  49. /**
  50. * Возвращает связь родительской категории
  51. *
  52. * @return BelongsTo
  53. */
  54. public function parent(): BelongsTo
  55. {
  56. return $this->belongsTo(self::class, 'parent_id')->withDefault();
  57. }
  58.  
  59. /**
  60. * Возвращает связь подкатегорий
  61. *
  62. * @return HasMany
  63. */
  64. public function children(): HasMany
  65. {
  66. return $this->hasMany(self::class, 'parent_id')->orderBy('sort');
  67. }
  68. }