File: D:/HostingSpaces/SBogers10/inzigd.komma.pro/app/Komma/Users/Models/User.php
<?php
namespace App\Komma\Users\Models;
use App\Komma\Addresses\AddressableInterface;
use App\Komma\Addresses\Models\Address;
use App\Komma\Components\Component\ComponentableInterface;
use App\Komma\Components\Component\ComponentableTrait;
use App\Komma\Kms\Core\Attributes\Models\Traits\HasThumbnailInterface;
use App\Komma\Kms\Core\Attributes\Models\Traits\HasThumbnailTrait;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Documents\Models\Document;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Kms\ActionLog\HasActionLogs;
use App\Komma\Kms\Core\Entities\HasSearchableAttributesForSidebarInterface;
use App\Komma\Shop\Orders\Models\Order;
use App\Notifications\KmsResetPasswordNotification;
use App\Notifications\SiteResetPasswordNotification;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
/**
* Class User
*
* @package App\Komma\Users\Models
* @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 $culture
* @property string $city
* @property string $postal_code
* @property int $house_number
* @property string $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 string|null $remember_token
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
* @property-read \App\Komma\Users\Models\Role $role
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereChamberOfCommerce($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCity($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCompanyCity($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCompanyCountry($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCompanyHouseNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCompanyName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCompanyStreet($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCompanyVatNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCompanyVatNumberValidated($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCompanyZipCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCountry($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereFailedLoginAttempts($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereFirstName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereHouseNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereLastLoginAttempt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereLastName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereRoleId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereStreet($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereTelephone($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereUsername($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereZipCode($value)
* @mixin \Eloquent
* @property string $company_postal_code
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCompanyPostalCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User wherePostalCode($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Shop\Orders\Models\Order[] $orders
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Kms\ActionLog\ActionLog[] $actions
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $documents
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $images
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Components\Component\Component[] $components
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereCulture($value)
* @property int $gender
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Addresses\Models\Address[] $addresses
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\User whereGender($value)
*/
final class User extends Authenticatable implements DocumentableInterface, DisplayNameInterface, HasThumbnailInterface, ComponentableInterface, HasSearchableAttributesForSidebarInterface {
use Notifiable;
use HasActionLogs;
use DocumentsTrait;
use DisplayNameTrait;
use HasThumbnailTrait;
use ComponentableTrait;
public const USERNAME_COLUMN_NAME = 'email';
public const PASSWORD_COLUMN_NAME = 'password';
protected $kmsClass = User::class;
/**
* 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');
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['username', 'email', 'password', 'first_name', 'last_name', 'failed_login_attempts', 'culture'];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['created_at', 'updated_at', 'last_login_attempt'];
/**
* Returns an array containing model attributes with their values,
* that will be used to search trough in the sidebar.
*
* @return array
*/
public function searchableAttributesForSidebar(): array
{
return [
'email' => $this->email
];
}
/**
* @return MorphMany
*/
public function documents():MorphMany
{
return $this->morphMany(Document::class, 'documentable');
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
if(strpos(url()->current(), 'kms') === false) {
//Send site reset mail
$this->notify(new SiteResetPasswordNotification($this, $token));
} else {
//Send kms reset mail
$this->notify(new KmsResetPasswordNotification($this, $token));
}
}
/**
* Returns the role of the user
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function role()
{
return $this->belongsTo(Role::class);
}
/**
* Shop Orders
*
* @return HasMany
*/
public function orders():HasMany
{
if(!config('app.isShop')) throw new \RuntimeException('Cannot get orders for a user since this installation isn\'t a shop');
return $this->hasMany(Order::class);
}
public function getAuthIdentifierName()
{
return $this->getKeyName();
}
/**
* @return null|string
*/
public function getDisplayName():?string
{
// If it is a new model the section name will filled by model.section.new
if(!$this->exists) return null;
return $this->first_name . ' ' . $this->last_name;
}
}