2018-10-15 16:00:48 +11:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2019-01-25 21:47:23 +11:00
|
|
|
use App\Models\Company;
|
2018-11-11 00:24:36 +11:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-01-25 21:47:23 +11:00
|
|
|
use Hashids\Hashids;
|
2018-11-12 18:52:20 +11:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2019-01-25 21:47:23 +11:00
|
|
|
use Laracasts\Presenter\PresentableTrait;
|
2018-10-15 16:00:48 +11:00
|
|
|
|
2018-11-02 21:54:46 +11:00
|
|
|
class Client extends BaseModel
|
2018-10-15 16:00:48 +11:00
|
|
|
{
|
2018-11-02 21:54:46 +11:00
|
|
|
use PresentableTrait;
|
2018-11-11 00:24:36 +11:00
|
|
|
use MakesHash;
|
2018-11-12 18:52:20 +11:00
|
|
|
use SoftDeletes;
|
2018-11-02 21:54:46 +11:00
|
|
|
|
|
|
|
|
protected $presenter = 'App\Models\Presenters\ClientPresenter';
|
|
|
|
|
|
2018-11-20 15:36:56 +11:00
|
|
|
//protected $appends = ['client_id'];
|
2018-11-11 00:24:36 +11:00
|
|
|
|
2018-11-12 18:52:20 +11:00
|
|
|
protected $guarded = [
|
2018-11-27 17:59:16 +11:00
|
|
|
'id',
|
|
|
|
|
'updated_at',
|
|
|
|
|
'created_at',
|
|
|
|
|
'deleted_at',
|
2018-11-27 18:24:26 +11:00
|
|
|
'contacts',
|
|
|
|
|
'primary_contact',
|
2019-01-25 21:47:23 +11:00
|
|
|
'q',
|
|
|
|
|
'company'
|
2018-11-11 00:24:36 +11:00
|
|
|
];
|
2018-11-27 17:59:16 +11:00
|
|
|
|
2019-01-22 20:47:26 +11:00
|
|
|
protected $with = ['contacts', 'primary_contact'];
|
|
|
|
|
|
2018-11-27 17:59:16 +11:00
|
|
|
//protected $dates = ['deleted_at'];
|
2018-11-12 18:52:20 +11:00
|
|
|
|
2018-11-21 19:28:07 +11:00
|
|
|
public function getHashedIdAttribute()
|
2018-11-11 00:24:36 +11:00
|
|
|
{
|
|
|
|
|
return $this->encodePrimaryKey($this->id);
|
|
|
|
|
}
|
2018-10-29 14:16:17 +11:00
|
|
|
|
|
|
|
|
public function contacts()
|
|
|
|
|
{
|
2019-01-25 21:47:23 +11:00
|
|
|
return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc');
|
2018-10-29 14:16:17 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function primary_contact()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(ClientContact::class)->whereIsPrimary(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 21:47:23 +11:00
|
|
|
public function company()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 16:00:48 +11:00
|
|
|
}
|