![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/medad.corals.io/Corals/modules/Medad/Models/ |
<?php namespace Corals\Modules\Medad\Models; use Corals\Foundation\Transformers\PresentableTrait; use Illuminate\Database\Eloquent\Builder; use Spatie\Activitylog\Traits\LogsActivity; class Company extends CompanyModel { use PresentableTrait, LogsActivity; /** * The "booted" method of the model. * * @return void */ protected static function booted() { static::addGlobalScope('parent', function (Builder $builder) { $builder->whereColumn('medad_companies.parent_id', 'medad_companies.id'); }); } /** * Model configuration. * @var string */ public $config = 'medad.models.company'; public function branches() { return $this->hasMany(Branch::class, 'parent_id', 'id'); } public function companyRelations() { return $this->belongsToMany(Company::class, 'medad_company_relation', 'company_id', 'second_company_id') ->withTimestamps() ->withPivot(['relation_type', 'properties']); } public function branchesRelation() { return $this->belongsToMany(CompanyRelation::class, 'company_relation_branches', 'branch_id', 'company_relation_id') ->withTimestamps() ->withPivot(['properties']) ->where('company_relation_branches.branch_id', optional($this->company)->id); } }