2018-10-15 07:00:48 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-03-02 22:44:08 +01:00
|
|
|
use App\DataMapper\ClientSettings;
|
2019-01-25 11:47:23 +01:00
|
|
|
use App\Models\Company;
|
2019-01-26 10:34:38 +01:00
|
|
|
use App\Models\Country;
|
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';
|
|
|
|
|
2019-03-02 22:44:08 +01:00
|
|
|
protected $appends = [
|
|
|
|
'client_settings_object'
|
|
|
|
];
|
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',
|
2019-01-26 10:34:38 +01:00
|
|
|
'company',
|
|
|
|
'country',
|
|
|
|
'shipping_country'
|
2018-11-10 14:24:36 +01:00
|
|
|
];
|
2018-11-27 07:59:16 +01:00
|
|
|
|
2019-01-26 10:34:38 +01:00
|
|
|
protected $with = ['contacts', 'primary_contact', 'country', 'shipping_country'];
|
2019-01-22 10:47:26 +01:00
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
protected $casts = [
|
|
|
|
'settings' => 'object'
|
|
|
|
];
|
|
|
|
|
2018-11-27 07:59:16 +01:00
|
|
|
//protected $dates = ['deleted_at'];
|
2018-11-12 08:52:20 +01:00
|
|
|
|
2019-03-02 22:44:08 +01:00
|
|
|
public function getClientSettingsObjectAttribute()
|
|
|
|
{
|
|
|
|
return new ClientSettings($this->settings);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-01-26 10:34:38 +01:00
|
|
|
public function country()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Country::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shipping_country()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Country::class, 'shipping_country_id', 'id');
|
|
|
|
}
|
|
|
|
|
2018-10-15 07:00:48 +02:00
|
|
|
}
|