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