diff --git a/app/Models/Company.php b/app/Models/Company.php index c1a6a191..043427e6 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -2,6 +2,7 @@ namespace App\Models; use App\Classes\General\Interfaces\Documentable; +use App\Classes\General\Interfaces\Contactable; use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceConfigurationsObject; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\SegmentConstants; @@ -25,7 +26,7 @@ use Illuminate\Support\Collection; * @property string street_two * @property integer billing_type */ -class Company extends AbstractModel implements Documentable +class Company extends AbstractModel implements Documentable, Contactable { use SoftDeletes; @@ -34,14 +35,6 @@ class Company extends AbstractModel implements Documentable protected $dates = ['deleted_at']; - /** - * @return HasMany - */ - public function contacts(): HasMany - { - return $this->HasMany(Contact::class, 'company_id'); - } - /** * @return HasMany */ @@ -63,7 +56,7 @@ class Company extends AbstractModel implements Documentable */ public function employees(): belongsToMany { - return $this->belongsToMany(User::class, (new Employee())->getTable(), 'company_id','user_id'); + return $this->belongsToMany(User::class, (new CompanyEmployee())->getTable(), 'company_id', 'user_id'); } /** @@ -74,6 +67,14 @@ class Company extends AbstractModel implements Documentable return $this->morphMany(Document::class, 'owner'); } + /** + * @return MorphMany + */ + public function contacts(): morphMany + { + return $this->morphMany(Contact::class, 'owner'); + } + /** * @return HasMany */ @@ -110,8 +111,4 @@ class Company extends AbstractModel implements Documentable $service->constants->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->whereIn('segment_id', $this->segments->pluck('id'))); }); } - } - - - diff --git a/app/Models/Contact.php b/app/Models/Contact.php index 0a54d3f7..f8ce6213 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -2,20 +2,20 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Eloquent\Relations\MorphTo; /** * Class Contact * @package App\Models * - * @property \App\Models\Country country_id - * @property \App\Models\Company company_id + * @property int owner_id + * @property string owner_type * @property string reference * @property string phone * @property string email * @property string wechat_id + * @property int default */ class Contact extends AbstractModel { @@ -26,18 +26,11 @@ class Contact extends AbstractModel protected $dates = ['deleted_at']; /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ - public function company(): HasOne + * @return \Illuminate\Database\Eloquent\Relations\MorphTo + */ + public function owner(): morphTo { - return $this->hasOne(Company::class); + return $this->morphTo(); } - /** - * @return belongsTo - **/ - public function country(): belongsTo - { - return $this->belongsTo(Country::class); - } } diff --git a/app/Models/User.php b/app/Models/User.php index d41cbb7f..5d5cfc2f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -60,8 +60,8 @@ class User extends AbstractModel implements /** * @return belongsToMany */ - public function company(): belongsToMany + public function companyModule(): belongsToMany { - return $this->belongsToMany(Company::class, (new Employee())->getTable(), 'user_id', 'company_id'); + return $this->belongsToMany(companyModule::class, (new CompanyEmployee())->getTable(), 'user_id', 'company_module_id'); } }