<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class Board
*
* @property int id
* @property int sort
* @property int parent_id
* @property string name
* @property int count_items
* @property int closed
* @property Collection children
* @property Board parent
*/
class Board extends BaseModel
{
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
/**
* Директория загрузки файлов
*
* @var string
*/
public $uploadPath = UPLOADS . '/boards';
/**
* Возвращает связь родительской категории
*
* @return BelongsTo
*/
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id')->withDefault();
}
/**
* Возвращает связь подкатегорий
*
* @return HasMany
*/
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id')->orderBy('sort');
}
}