53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Commons;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use App\Traits\BelongsToTenant;
|
|
use App\Traits\ModelTrait;
|
|
|
|
class Department extends Model
|
|
{
|
|
use SoftDeletes, BelongsToTenant, ModelTrait;
|
|
|
|
protected $table = 'departments';
|
|
|
|
protected $fillable = [
|
|
'tenant_id','code','name','description','is_active','sort_order',
|
|
'created_by','updated_by','deleted_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'tenant_id' => 'integer',
|
|
'is_active' => 'integer',
|
|
'sort_order'=> 'integer',
|
|
];
|
|
|
|
/** Relations */
|
|
public function departmentUsers()
|
|
{
|
|
return $this->hasMany(DepartmentUser::class, 'department_id');
|
|
}
|
|
|
|
public function users()
|
|
{
|
|
// User 네임스페이스가 다르면 여기만 맞춰줘.
|
|
return $this->belongsToMany(\App\Models\User::class, 'department_user', 'department_id', 'user_id')
|
|
->withPivot(['tenant_id','is_primary','joined_at','left_at','created_at','updated_at','deleted_at'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function departmentPermissions()
|
|
{
|
|
return $this->hasMany(DepartmentPermission::class, 'department_id');
|
|
}
|
|
|
|
public function permissions()
|
|
{
|
|
return $this->belongsToMany(\Spatie\Permission\Models\Permission::class, 'department_permissions', 'department_id', 'permission_id')
|
|
->withPivot(['tenant_id','menu_id','is_allowed','created_at','updated_at','deleted_at'])
|
|
->withTimestamps();
|
|
}
|
|
}
|