2020-01-20 02:31:58 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
use App\Notifications\ClientContactResetPassword;
|
2020-01-20 02:31:58 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Contracts\Translation\HasLocalePreference;
|
2020-10-01 12:49:47 +02:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-01-20 02:31:58 +01:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Laracasts\Presenter\PresentableTrait;
|
|
|
|
|
|
|
|
class VendorContact extends Authenticatable implements HasLocalePreference
|
|
|
|
{
|
|
|
|
use Notifiable;
|
|
|
|
use MakesHash;
|
|
|
|
use PresentableTrait;
|
|
|
|
use SoftDeletes;
|
2020-10-01 12:49:47 +02:00
|
|
|
use HasFactory;
|
2020-01-20 02:31:58 +01:00
|
|
|
|
|
|
|
/* Used to authenticate a vendor */
|
|
|
|
protected $guard = 'vendor';
|
|
|
|
|
2020-07-16 13:01:39 +02:00
|
|
|
protected $touches = ['vendor'];
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
/* Allow microtime timestamps */
|
|
|
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
|
|
|
|
|
|
|
protected $dates = [
|
2020-09-06 11:38:10 +02:00
|
|
|
'deleted_at',
|
2020-01-20 02:31:58 +01:00
|
|
|
];
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
protected $appends = [
|
2020-09-06 11:38:10 +02:00
|
|
|
'hashed_id',
|
2020-01-20 02:31:58 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
protected $with = [
|
2020-02-06 10:35:51 +01:00
|
|
|
// 'vendor',
|
|
|
|
// 'company'
|
2020-01-20 02:31:58 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'phone',
|
|
|
|
'custom_value1',
|
|
|
|
'custom_value2',
|
|
|
|
'custom_value3',
|
|
|
|
'custom_value4',
|
|
|
|
'email',
|
|
|
|
'is_primary',
|
2020-10-31 06:35:05 +01:00
|
|
|
'vendor_id',
|
2020-01-20 02:31:58 +01:00
|
|
|
];
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-05-06 13:49:42 +02:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
return self::class;
|
2020-05-06 13:49:42 +02:00
|
|
|
}
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
public function getHashedIdAttribute()
|
|
|
|
{
|
|
|
|
return $this->encodePrimaryKey($this->id);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
public function getContactIdAttribute()
|
|
|
|
{
|
|
|
|
return $this->encodePrimaryKey($this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function vendor()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Vendor::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function primary_contact()
|
|
|
|
{
|
|
|
|
return $this->where('is_primary', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sendPasswordResetNotification($token)
|
|
|
|
{
|
|
|
|
$this->notify(new ClientContactResetPassword($token));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function preferredLocale()
|
|
|
|
{
|
|
|
|
$languages = Cache::get('languages');
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
return $languages->filter(function ($item) {
|
|
|
|
return $item->id == $this->client->getSetting('language_id');
|
|
|
|
})->first()->locale;
|
|
|
|
|
|
|
|
//$lang = Language::find($this->client->getSetting('language_id'));
|
|
|
|
|
|
|
|
//return $lang->locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the model for a bound value.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param mixed $value
|
|
|
|
* @param null $field
|
|
|
|
* @return Model|null
|
2020-01-20 02:31:58 +01:00
|
|
|
*/
|
2020-11-25 15:19:52 +01:00
|
|
|
public function resolveRouteBinding($value, $field = null)
|
2020-01-20 02:31:58 +01:00
|
|
|
{
|
|
|
|
return $this
|
|
|
|
->withTrashed()
|
|
|
|
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
|
|
|
}
|
|
|
|
}
|