mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-14 07:02:34 +01:00
ba75a44eb8
* Adopt Laravel coding style The Laravel framework adopts the PSR-2 coding style with some additions. Laravel apps *should* adopt this coding style as well. However, Shift allows you to customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config to your project. You may use [Shift's .php_cs][2] file as a base. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 * Shift bindings PHP 5.5.9+ adds the new static `class` property which provides the fully qualified class name. This is preferred over using class name strings as these references are checked by the parser. * Shift core files * Shift to Throwable * Add laravel/ui dependency * Unindent vendor mail templates * Shift config files * Default config files In an effort to make upgrading the constantly changing config files easier, Shift defaulted them so you can review the commit diff for changes. Moving forward, you should use ENV variables or create a separate config file to allow the core config files to remain automatically upgradeable. * Shift Laravel dependencies * Shift cleanup * Upgrade to Laravel 7 Co-authored-by: Laravel Shift <shift@laravelshift.com>
142 lines
3.3 KiB
PHP
142 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://opensource.org/licenses/AAL
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\Language;
|
|
use App\Models\User;
|
|
use App\Notifications\ClientContactResetPassword;
|
|
use App\Notifications\ClientContactResetPassword as ResetPasswordNotification;
|
|
use App\Utils\Traits\MakesHash;
|
|
use Hashids\Hashids;
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Contracts\Translation\HasLocalePreference;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Laracasts\Presenter\PresentableTrait;
|
|
|
|
class VendorContact extends Authenticatable implements HasLocalePreference
|
|
{
|
|
use Notifiable;
|
|
use MakesHash;
|
|
use PresentableTrait;
|
|
use SoftDeletes;
|
|
|
|
/* Used to authenticate a vendor */
|
|
protected $guard = 'vendor';
|
|
|
|
protected $touches = ['vendor'];
|
|
|
|
/* Allow microtime timestamps */
|
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
|
|
|
protected $dates = [
|
|
'deleted_at',
|
|
];
|
|
|
|
protected $appends = [
|
|
'hashed_id',
|
|
];
|
|
|
|
protected $with = [
|
|
// 'vendor',
|
|
// 'company'
|
|
];
|
|
|
|
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',
|
|
];
|
|
|
|
public function getEntityType()
|
|
{
|
|
return self::class;
|
|
}
|
|
|
|
public function getHashedIdAttribute()
|
|
{
|
|
return $this->encodePrimaryKey($this->id);
|
|
}
|
|
|
|
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');
|
|
|
|
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.
|
|
*
|
|
* @param mixed $value
|
|
* @return \Illuminate\Database\Eloquent\Model|null
|
|
*/
|
|
public function resolveRouteBinding($value, $field = NULL)
|
|
{
|
|
return $this
|
|
->withTrashed()
|
|
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
|
}
|
|
}
|