<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class OfficesDepartment extends Model
{
    protected $fillable = [
        'office_admin_name',
        'office_admin_image',
        'office_admin_description',
        'office_department_id',
        'office_admin_email'
    ];

    public function officeDepartment()
    {
        return $this->belongsTo(Offices::class, 'office_department_id');
    }
    public function scopeSearch($query, $term)
    {
        $term = "%$term%";
    
        $query->where(function ($query) use ($term) {
            $query->where('office_admin_name', 'like', $term)
                  ->orWhereHas('officeDepartment', function ($q) use ($term) {
                      $q->where('description', 'like', $term);
                  });
        });
    }
}
