2021-02-17 17:40:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
class BusinessSector extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'order',
|
2021-02-18 17:29:54 +01:00
|
|
|
'parent_id',
|
2021-02-17 17:40:35 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function employees()
|
|
|
|
|
{
|
2021-02-18 17:29:54 +01:00
|
|
|
return $this->belongsToMany(Employees::class, 'sectors_employees', 'business_sector_id', 'employee_id')->orderBy('order', 'ASC');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function parent()
|
|
|
|
|
{
|
2023-08-21 15:24:32 +02:00
|
|
|
return $this->hasOne(self::class, 'id', 'parent_id');
|
2021-02-18 17:29:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function children()
|
|
|
|
|
{
|
2023-08-21 15:24:32 +02:00
|
|
|
return $this->hasMany(self::class, 'parent_id', 'id');
|
2021-02-17 17:40:35 +01:00
|
|
|
}
|
|
|
|
|
}
|