From 99b173c4c846c20b5a7cf968d1b6df3aaeb6096e Mon Sep 17 00:00:00 2001 From: weichien00 Date: Thu, 8 Jul 2021 01:07:49 +0800 Subject: [PATCH] add: new model files, CompanyEmployee and CompanyModule based on new tables. --- app/Models/CompanyEmployee.php | 36 ++++++++++++ app/Models/CompanyModule.php | 103 +++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 app/Models/CompanyEmployee.php create mode 100644 app/Models/CompanyModule.php diff --git a/app/Models/CompanyEmployee.php b/app/Models/CompanyEmployee.php new file mode 100644 index 00000000..fc6ebfa4 --- /dev/null +++ b/app/Models/CompanyEmployee.php @@ -0,0 +1,36 @@ +HasMany(CompanyModule::class, 'company_module_id', 'id'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + **/ + public function user(): HasOne + { + return $this->hasOne(User::class, 'user_id', 'id'); + } +} diff --git a/app/Models/CompanyModule.php b/app/Models/CompanyModule.php new file mode 100644 index 00000000..9c6026d8 --- /dev/null +++ b/app/Models/CompanyModule.php @@ -0,0 +1,103 @@ +morphMany(Contact::class, 'owner'); + } + + /** + * @return belongsToMany + */ + public function employees(): belongsToMany + { + return $this->belongsToMany(User::class, (new CompanyEmployee())->getTable(), 'company_module_id', 'user_id'); + } + + // /** + // * @return HasMany + // */ + // public function addresses(): HasMany + // { + // return $this->HasMany(Address::class, 'company_id'); + // } + + // /** + // * @return belongsToMany + // */ + // public function segments(): belongsToMany + // { + // return $this->belongsToMany(Segment::class, (new SegmentCompany())->getTable(), 'company_id', 'segment_id'); + // } + + // /** + // * @return MorphMany + // */ + // public function documents(): morphMany + // { + // return $this->morphMany(Document::class, 'owner'); + // } + + // /** + // * @return HasMany + // */ + // public function banks(): HasMany + // { + // return $this->HasMany(Bank::class, 'company_id'); + // } + + // /** + // * @return HasMany + // */ + // public function bookings(): HasMany + // { + // return $this->HasMany(Booking::class, 'company_id'); + // } + + // /** + // * @return Builder + // */ + // public function services(): Builder { + // return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function($query) { + // $query->Where(function($query){ + // $query->where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->is_active', true); + // })->orWhere(function($query) { + // $query->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->is_active', true)->whereIn('segment_id', $this->segments->pluck('id')); + // }); + // }); + // } + + // public function servicesConfigurations(): Collection { + // return $this->services()->get()->map(function($service) { + // return new ServiceConfigurationsObject($service, + // $service->constants->where('reference', SegmentConstants::SERVICE_TYPE)->first(), + // $service->constants->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->whereIn('segment_id', $this->segments->pluck('id'))); + // }); + // } + +}