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