File: D:/HostingSpaces/Eurotools/euro-tools.nl/app/KommaApp/Users/Models/User.php
<?php
namespace App\KommaApp\Users\Models;
use App\KommaApp\Images\Models\Image;
use App\KommaApp\Kms\ActionLog\HasActions;
use App\KommaApp\Languages\Models\Language;
use App\KommaApp\Shop\Notifications\CustomerApproved;
use App\Notifications\ResetPasswordNotification;
use App\Notifications\SiteResetPasswordNotification;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
/**
* Class User
*
* @package App\KommaApp\Users\Models
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Images\Models\Image[] $images
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
* @property-read \App\KommaApp\Users\Models\Role $role
* @mixin \Eloquent
* @property int $id
* @property int $role_id
* @property string $username
* @property string $password
* @property string $email
* @property string|null $first_name
* @property string|null $last_name
* @property \Carbon\Carbon $last_login_attempt
* @property int $failed_login_attempts
* @property int $telephone
* @property string $gender
* @property string $shipping_country
* @property string $shipping_city
* @property string $shipping_zip_code
* @property int $shipping_house_number
* @property string $shipping_street
* @property int $company_vat_number_validated
* @property string $company_vat_number
* @property string $company_country
* @property string $company_zip_code
* @property string $company_city
* @property string $company_house_number
* @property string $company_street
* @property string $chamber_of_commerce
* @property string $company_name
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @property \Carbon\Carbon|null $approved_at
* @property string|null $remember_token
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereChamberOfCommerce($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCompanyCity($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCompanyCountry($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCompanyHouseNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCompanyName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCompanyStreet($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCompanyVatNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCompanyVatNumberValidated($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCompanyZipCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereFailedLoginAttempts($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereFirstName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereLastLoginAttempt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereLastName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereRoleId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereShippingCity($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereShippingCountry($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereShippingHouseNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereShippingStreet($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereShippingZipCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereTelephone($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereGender($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereApprovedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereUsername($value)
* @property int $approved
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereApproved($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Kms\ActionLog\ActionLog[] $actions
*/
class User extends Authenticatable {
use Notifiable;
use HasActions;
// protected $admin = 1;
protected $kmsClass = User::class;
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
protected $fillable = [
'username',
'email',
'password',
'first_name',
'last_name',
'failed_login_attempts',
'approved',
'telephone',
'gender',
'shipping_country',
'shipping_city',
'shipping_zip_code',
'shipping_house_number',
'shipping_street',
'differentShippingAddress',
'company_vat_number_validated',
'company_vat_number',
'company_country',
'company_zip_code',
'company_city',
'company_house_number',
'company_street',
'chamber_of_commerce',
'company_name',
'locale'
];
public function getDates()
{
return array('created_at', 'updated_at', 'approved_at','last_login_attempt');
}
/**
* Get the images from the current user
*
* @return \Illuminate\Database\Eloquent\Relations\hasMany
*/
public function images()
{
/**
* On the Image model is an MorphTo relation
* By using a hasMany relation:
* where the imageable_type is filled in with the KmsClass
* And the imageable_id is set as the foreign_id,
* we can collect the images of the given model directly.
*
*/
return $this->hasMany(Image::class, 'imageable_id')
->where('imageable_type', '=', $this->kmsClass);
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$currentLanguage = \App::getLanguage();
$iso2Country = ($this->locale == '' || $this->locale == null) ? 'en' : strtolower($this->locale) ;
$language = Language::where('iso_2', '=', $iso2Country)->first();
\App::setLanguage($language);
if($this->approved_at != '') {
$this->notify(new SiteResetPasswordNotification($token));
\Log::debug('Sent resetPasswordNotification for user with id: ' . $this->attributes['id'].' token: '.$token);
} else {
$this->approved_at = Carbon::now();
$this->approved = 1;
$this->save();
$this->notify((new CustomerApproved($this, $token)));
\Log::debug('Sent CustomerApproved password setup email for user with id: ' . $this->attributes['id'].' token: '.$token);
}
\App::setLanguage($currentLanguage);
}
/**
* Returns the role of the user
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function role()
{
return $this->belongsTo(Role::class);
}
public function getSalutation($abbreviated = false)
{
$gender = $this->gender;
switch ($gender)
{
case 'male':
case 'female':
return $abbreviated ? __('salutations.'.$gender.'.abbreviated.general') : __('salutations.'.$gender.'.full.general');
break;
default:
return $abbreviated ? __('salutations.unknown.abbreviated.general') : __('salutations.unknown.full.general');
break;
}
}
public function getAuthIdentifierName()
{
return $this->getKeyName();
}
public function __get($key)
{
if($key == "title") {
return $this->first_name." ".$this->last_name;
}
return parent::__get($key);
}
}