初始化项目
This commit is contained in:
53
app/Models/Auth/Department.php
Normal file
53
app/Models/Auth/Department.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Department extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'auth_departments';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'parent_id',
|
||||
'leader',
|
||||
'phone',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'parent_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取子部门
|
||||
*/
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(Department::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取父部门
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门下的用户
|
||||
*/
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class, 'department_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user