add: new model files, CompanyEmployee and CompanyModule based on new tables.

This commit is contained in:
weichien00
2021-07-08 01:07:49 +08:00
parent 7f0d5843f5
commit 99b173c4c8
2 changed files with 139 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* Class CompanyEmployee
* @package App\Models
*
* @property \App\Models\companyModule company_module_id
* @property \App\Models\User user_id
* @property integer role_id
* @property integer status
*/
class CompanyEmployee extends AbstractModel
{
protected $table = 'company_employees';
/**
* @return HasMany
*/
public function companyModule(): HasMany
{
return $this->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');
}
}
+103
View File
@@ -0,0 +1,103 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class CompanyModule
* @package App\Models
*
* @property \App\Models\Company company_id
* @property integer type
* @property integer status
*/
class CompanyModule extends AbstractModel
{
use SoftDeletes;
protected $table = 'company_modules';
protected $dates = ['deleted_at'];
/**
* @return MorphMany
*/
public function contacts(): morphMany
{
return $this->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')));
// });
// }
}