/
DATKAI
/
ITCUP
Обзор
Документация
Войти
/
DATKAI
/
ITCUP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
app/Models/Department.php
50 строк
1 KB
ITCUP Admin
Initial commit: ITCUP — базовая структура, инвентарь, задачник, пользователи
17 апр 2026, 09:29
17 апр 2026, 09:29
a2ae386
Код
Авторство
О чём код?
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; class Department extends Model { protected $fillable = [ 'parent_id', 'branch_id', 'name', 'code', 'description', 'sort_order', ]; public function parent(): BelongsTo { return $this->belongsTo(Department::class, 'parent_id'); } public function children(): HasMany { return $this->hasMany(Department::class, 'parent_id'); } public function branch(): BelongsTo { return $this->belongsTo(Branch::class); } public function users(): HasMany { return $this->hasMany(User::class); } public function getFullNameAttribute(): string { $parts = [$this->name]; $p = $this->parent; while ($p) { array_unshift($parts, $p->name); $p = $p->parent; } return implode(' → ', $parts); } }