1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00
invoiceninja/app/Models/Client.php

71 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use App\Models\Company;
2019-01-26 10:34:38 +01:00
use App\Models\Country;
use App\Utils\Traits\MakesHash;
use Hashids\Hashids;
use Illuminate\Database\Eloquent\SoftDeletes;
use Laracasts\Presenter\PresentableTrait;
class Client extends BaseModel
{
use PresentableTrait;
use MakesHash;
use SoftDeletes;
protected $presenter = 'App\Models\Presenters\ClientPresenter';
//protected $appends = ['client_id'];
protected $guarded = [
'id',
'updated_at',
'created_at',
'deleted_at',
'contacts',
'primary_contact',
'q',
2019-01-26 10:34:38 +01:00
'company',
'country',
'shipping_country'
];
2019-01-26 10:34:38 +01:00
2019-01-26 10:34:38 +01:00
protected $with = ['contacts', 'primary_contact', 'country', 'shipping_country'];
//protected $dates = ['deleted_at'];
public function getHashedIdAttribute()
{
return $this->encodePrimaryKey($this->id);
}
public function contacts()
{
return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc');
}
public function primary_contact()
{
return $this->hasMany(ClientContact::class)->whereIsPrimary(true);
}
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');
}
}