2018-10-15 16:00:48 +11:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2020-01-07 11:13:47 +11:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
|
*/
|
2018-10-15 16:00:48 +11:00
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2019-07-08 10:08:57 +10:00
|
|
|
use App\Models\Company;
|
2019-11-04 11:22:59 +11:00
|
|
|
use App\Models\Language;
|
2019-07-08 10:08:57 +10:00
|
|
|
use App\Models\User;
|
2019-07-18 09:45:18 +10:00
|
|
|
use App\Notifications\ClientContactResetPassword as ResetPasswordNotification;
|
|
|
|
|
use App\Notifications\ClientContactResetPassword;
|
2018-11-20 15:36:56 +11:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2018-11-02 21:54:46 +11:00
|
|
|
use Hashids\Hashids;
|
2018-10-15 16:00:48 +11:00
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
2019-11-04 11:22:59 +11:00
|
|
|
use Illuminate\Contracts\Translation\HasLocalePreference;
|
2018-11-27 17:59:16 +11:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2018-10-15 16:00:48 +11:00
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2018-11-20 15:36:56 +11:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
2019-11-07 09:57:09 +11:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2019-08-08 18:13:32 +10:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-11-04 11:22:59 +11:00
|
|
|
use Laracasts\Presenter\PresentableTrait;
|
2018-10-15 16:00:48 +11:00
|
|
|
|
2019-11-04 11:22:59 +11:00
|
|
|
class ClientContact extends Authenticatable implements HasLocalePreference
|
2018-10-15 16:00:48 +11:00
|
|
|
{
|
|
|
|
|
use Notifiable;
|
2018-11-20 15:36:56 +11:00
|
|
|
use MakesHash;
|
2018-11-21 19:28:07 +11:00
|
|
|
use PresentableTrait;
|
2018-11-27 17:59:16 +11:00
|
|
|
use SoftDeletes;
|
2018-11-21 19:28:07 +11:00
|
|
|
|
2019-07-09 20:32:26 +10:00
|
|
|
/* Used to authenticate a contact */
|
2018-10-15 16:00:48 +11:00
|
|
|
protected $guard = 'contact';
|
|
|
|
|
|
2019-07-09 20:32:26 +10:00
|
|
|
/* Allow microtime timestamps */
|
2019-07-09 10:01:29 +10:00
|
|
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
|
|
|
|
|
2019-08-14 10:15:21 +10:00
|
|
|
protected $presenter = 'App\Models\Presenters\ClientContactPresenter';
|
|
|
|
|
|
|
|
|
|
protected $dates = [
|
|
|
|
|
'deleted_at'
|
|
|
|
|
];
|
2020-03-23 18:10:42 +01:00
|
|
|
|
2019-08-02 10:31:48 +10:00
|
|
|
protected $appends = [
|
|
|
|
|
'hashed_id'
|
|
|
|
|
];
|
|
|
|
|
|
2019-08-14 10:15:21 +10:00
|
|
|
protected $with = [
|
2020-02-06 20:35:51 +11:00
|
|
|
// 'client',
|
|
|
|
|
// 'company'
|
2019-08-14 10:15:21 +10:00
|
|
|
];
|
|
|
|
|
|
2019-10-02 19:04:27 +10:00
|
|
|
protected $casts = [
|
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
|
'deleted_at' => 'timestamp',
|
|
|
|
|
];
|
|
|
|
|
|
2019-07-09 20:32:26 +10:00
|
|
|
protected $hidden = [
|
2019-12-31 08:59:12 +11:00
|
|
|
'password',
|
2019-07-09 20:32:26 +10:00
|
|
|
'remember_token',
|
2019-08-08 21:07:26 +10:00
|
|
|
'user_id',
|
|
|
|
|
'company_id',
|
|
|
|
|
'client_id',
|
|
|
|
|
'google_2fa_secret',
|
|
|
|
|
'id',
|
|
|
|
|
'oauth_provider_id',
|
|
|
|
|
'oauth_user_id',
|
|
|
|
|
'token',
|
2019-07-09 20:32:26 +10:00
|
|
|
];
|
|
|
|
|
|
2019-06-26 14:04:10 +10:00
|
|
|
protected $fillable = [
|
|
|
|
|
'first_name',
|
|
|
|
|
'last_name',
|
|
|
|
|
'phone',
|
|
|
|
|
'custom_value1',
|
|
|
|
|
'custom_value2',
|
|
|
|
|
'custom_value3',
|
|
|
|
|
'custom_value4',
|
|
|
|
|
'email',
|
2019-12-08 18:33:44 +11:00
|
|
|
'is_primary',
|
2018-10-15 16:00:48 +11:00
|
|
|
];
|
2020-03-23 18:10:42 +01:00
|
|
|
|
2019-08-14 10:15:21 +10:00
|
|
|
public function getHashedIdAttribute()
|
|
|
|
|
{
|
|
|
|
|
return $this->encodePrimaryKey($this->id);
|
|
|
|
|
}
|
2020-03-23 18:10:42 +01:00
|
|
|
|
2019-07-09 20:32:26 +10:00
|
|
|
/**/
|
2018-11-20 15:36:56 +11:00
|
|
|
public function getRouteKeyName()
|
|
|
|
|
{
|
|
|
|
|
return 'contact_id';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getContactIdAttribute()
|
|
|
|
|
{
|
|
|
|
|
return $this->encodePrimaryKey($this->id);
|
|
|
|
|
}
|
2018-10-29 14:16:17 +11:00
|
|
|
|
2019-08-08 18:13:32 +10:00
|
|
|
public function setAvatarAttribute($value)
|
2019-08-08 10:22:54 +10:00
|
|
|
{
|
2019-12-31 08:59:12 +11:00
|
|
|
if (!filter_var($value, FILTER_VALIDATE_URL) && $value) {
|
2019-08-08 18:13:32 +10:00
|
|
|
$this->attributes['avatar'] = url('/') . $value;
|
2019-12-31 08:59:12 +11:00
|
|
|
} else {
|
2019-08-08 18:13:32 +10:00
|
|
|
$this->attributes['avatar'] = $value;
|
2019-12-31 08:59:12 +11:00
|
|
|
}
|
2019-08-08 10:22:54 +10:00
|
|
|
}
|
|
|
|
|
|
2018-10-29 14:16:17 +11:00
|
|
|
public function client()
|
|
|
|
|
{
|
2019-11-25 20:38:55 +11:00
|
|
|
return $this->belongsTo(Client::class)->withTrashed();
|
2018-10-29 14:16:17 +11:00
|
|
|
}
|
|
|
|
|
|
2018-11-02 21:54:46 +11:00
|
|
|
public function primary_contact()
|
|
|
|
|
{
|
2019-07-10 11:42:34 +10:00
|
|
|
return $this->where('is_primary', true);
|
2018-11-02 21:54:46 +11:00
|
|
|
}
|
|
|
|
|
|
2019-07-08 10:08:57 +10:00
|
|
|
public function company()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
|
{
|
2019-11-25 20:38:55 +11:00
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
2019-07-08 10:08:57 +10:00
|
|
|
}
|
|
|
|
|
|
2019-07-18 09:45:18 +10:00
|
|
|
public function sendPasswordResetNotification($token)
|
|
|
|
|
{
|
|
|
|
|
$this->notify(new ClientContactResetPassword($token));
|
|
|
|
|
}
|
2019-11-04 11:22:59 +11:00
|
|
|
|
|
|
|
|
public function preferredLocale()
|
|
|
|
|
{
|
2019-11-06 09:52:57 +11:00
|
|
|
$languages = Cache::get('languages');
|
2020-03-23 18:10:42 +01:00
|
|
|
|
2019-12-31 08:59:12 +11:00
|
|
|
return $languages->filter(function ($item) {
|
2019-11-06 09:52:57 +11:00
|
|
|
return $item->id == $this->client->getSetting('language_id');
|
|
|
|
|
})->first()->locale;
|
2019-11-04 11:22:59 +11:00
|
|
|
|
2019-11-06 09:52:57 +11:00
|
|
|
//$lang = Language::find($this->client->getSetting('language_id'));
|
|
|
|
|
|
|
|
|
|
//return $lang->locale;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 23:22:14 +11:00
|
|
|
public function routeNotificationForMail($notification)
|
|
|
|
|
{
|
|
|
|
|
return $this->email;
|
|
|
|
|
}
|
2019-11-06 09:52:57 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the model for a bound value.
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Model|null
|
|
|
|
|
*/
|
|
|
|
|
public function resolveRouteBinding($value)
|
|
|
|
|
{
|
|
|
|
|
return $this
|
|
|
|
|
->withTrashed()
|
|
|
|
|
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
2019-11-04 11:22:59 +11:00
|
|
|
}
|
2020-03-23 18:10:42 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return mixed|string
|
|
|
|
|
*/
|
|
|
|
|
public function avatar()
|
|
|
|
|
{
|
2020-03-26 14:23:57 +11:00
|
|
|
if ($this->avatar) {
|
2020-03-23 18:10:42 +01:00
|
|
|
return $this->avatar;
|
2020-03-26 14:23:57 +11:00
|
|
|
}
|
2020-03-23 18:10:42 +01:00
|
|
|
|
|
|
|
|
return asset('images/svg/user.svg');
|
|
|
|
|
}
|
2018-10-15 16:00:48 +11:00
|
|
|
}
|