Job_title.php 1.22 KB
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Job_title extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'is_remove',
        'parent_id',
        'sort',
        'position_id',
        'is_bd'
       ];
    /*
       * Связь модели Вакансии (Ad_employer) с моделью Должности (Job_title)
       */
    public function Ads() {
        return $this->belongsToMany(Ad_employer::class, 'ad_jobs');
    }

    /*
     * Связь таблицы job_titles с таблицей job_titles через ключ parent_id
       многие-к-одному
    */
    public function parent() {
        return $this->belongsTo(Job_title::class, 'parent_id');
    }

    public function scopeActive($query) {
        return $query->where('is_remove', '=', '0');
    }

    public function scopeBdif($query) {
        return $query->where(function($q) {
            $q->where('is_bd', '1')->orwhere('is_bd', '2');
        });
    }

    public function scopeNotbdif($query) {
        return $query->where(function($q) {
            $q->where('is_bd', '0')->orwhere('is_bd', '2');
        });
    }
}