123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- /**
- * Created by IntelliJ IDEA.
- * User: kelyliang
- * Date: 2024/2/18
- * Time: 下午 03:52
- */
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- class Department extends Model
- {
- use HasFactory;
- protected $table = 'department';
- // 设置主键(可选,默认是'id')
- protected $primaryKey = 'id';
- // 定义允许批量赋值的字段(可选)
- protected $fillable = ['name', 'parent_id','manager_id'];
- // 例如,一个部门可能有多个子部门
- public function children()
- {
- return $this->hasMany(Department::class, 'parent_id');
- }
- // 或者,一个部门可能属于另一个部门
- public function parent()
- {
- return $this->belongsTo(Department::class, 'parent_id');
- }
- }
|