update: Company,Contact,User model files - change accordingly based on new db structure.

This commit is contained in:
weichien00
2021-07-08 01:13:37 +08:00
parent 644339a224
commit 0e057a8832
3 changed files with 21 additions and 31 deletions
+11 -14
View File
@@ -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')));
});
}
}
+8 -15
View File
@@ -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);
}
}
+2 -2
View File
@@ -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');
}
}