belongsTo(Branch::class)->withTrashed(); } protected static function booted() { static::addGlobalScope(new BranchScope); if (auth()->check() && auth()->user()->accessToMultiBranch()) { static::addGlobalScope('withBranch', function ($builder) { $builder->with('branch:id,name'); }); } } public static function boot() { parent::boot(); static::creating(function ($model) { $model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id; }); } public function employee() { return $this->belongsTo(Employee::class); } public function leave_type() { return $this->belongsTo(LeaveType::class); } public function department() { return $this->belongsTo(Department::class); } }