Your IP : 216.73.216.79


Current Path : /var/www/html/dynaweb-cms-v1/app/Models/Backend/
Upload File :
Current File : /var/www/html/dynaweb-cms-v1/app/Models/Backend/ContentDirectoryDepartment.php

<?php

namespace App\Models\Backend;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Table;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

#[Table('content_directory_departments', key: 'directory_department_id')]
#[Fillable([
    'directory_department_code',
    'directory_department_name',
    'directory_department_name_en',
    'directory_department_parent_id',
    'directory_department_sort',
    'created_by',
    'updated_by',
])]
class ContentDirectoryDepartment extends Model
{
    use HasFactory;

    protected function casts(): array
    {
        return [
            'directory_department_parent_id' => 'integer',
            'directory_department_sort' => 'integer',
            'created_at' => 'datetime',
            'updated_at' => 'datetime',
        ];
    }

    public function parent(): BelongsTo
    {
        return $this->belongsTo(self::class, 'directory_department_parent_id', 'directory_department_id');
    }

    public function children(): HasMany
    {
        return $this->hasMany(self::class, 'directory_department_parent_id', 'directory_department_id')
            ->orderBy('directory_department_sort');
    }

    public function staff(): HasMany
    {
        return $this->hasMany(ContentDirectoryStaff::class, 'directory_staff_department_id', 'directory_department_id');
    }
}