65 lines
1.2 KiB
PHP
65 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Organization extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'code',
|
|
'name',
|
|
'type',
|
|
'status',
|
|
'description',
|
|
'part_of',
|
|
'main_address_id',
|
|
];
|
|
|
|
public $with = [
|
|
'metas'
|
|
];
|
|
|
|
public $appends = [
|
|
'meta'
|
|
];
|
|
|
|
public function getMetaAttribute()
|
|
{
|
|
$orgMeta = [];
|
|
foreach ($this->metas as $meta) {
|
|
$orgMeta[$meta->type] = $meta->value;
|
|
}
|
|
|
|
return (object) $orgMeta;
|
|
}
|
|
|
|
public function addresses()
|
|
{
|
|
return $this->morphMany(Address::class, 'addressable');
|
|
}
|
|
|
|
public function currentAddress()
|
|
{
|
|
return $this->belongsTo(Address::class, 'main_address_id');
|
|
}
|
|
|
|
public function parent()
|
|
{
|
|
return $this->belongsTo(Organization::class, 'part_of', 'id');
|
|
}
|
|
|
|
public function metas()
|
|
{
|
|
return $this->morphMany(Meta::class, 'metaable');
|
|
}
|
|
|
|
public function practitionerRoles()
|
|
{
|
|
return $this->hasMany(PractitionerRole::class, 'organization_id');
|
|
}
|
|
}
|