File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Users/SiteUser.php
<?php declare(strict_types=1);
namespace App\Users;
use App\Addresses\AddressInterface;
use App\Notifications\SiteUserResetPasswordNotification;
use App\Notifications\SiteUserSetPasswordNotification;
use App\Orders\Models\Order;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Notifications\Notifiable;
use Komma\KMS\ActionLog\HasActionLogs;
use Komma\KMS\Auth\CanSetAndResetPassword;
use Komma\KMS\Core\Attributes\Models\Traits\HasThumbnailInterface;
use Komma\KMS\Core\Attributes\Models\Traits\HasThumbnailTrait;
use Komma\KMS\Core\Entities\DisplayNameInterface;
use Komma\KMS\Core\Entities\DisplayNameTrait;
use Komma\KMS\Core\Entities\HasSearchableAttributesForSidebarInterface;
use Komma\KMS\Core\HasEmptyPasswordTrait;
use Komma\KMS\Documents\DocumentsTrait;
use Komma\KMS\Documents\Kms\DocumentableInterface;
use Komma\KMS\Documents\Models\Document;
use Komma\KMS\Users\RoleTrait;
use Illuminate\Foundation\Auth\User as Authenticatable;
/**
* App\Users\SiteUser
*
* @property int $id
* @property int|null $role
* @property string $password
* @property string $email
* @property string $telephone
* @property string|null $first_name
* @property string|null $last_name_prefix
* @property string|null $last_name
* @property string $culture
* @property int $gender
* @property int $is_guest When false, this user did not create the account himself (Ordered as guest for example). When true, he did register.
* @property int|null $account_address_id
* @property int|null $shipping_address_id Whether or not the address will be used as the default shipping address
* @property int|null $invoice_address_id Whether or not the address will be used as the default invoice address
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $remember_token
* @property-read \App\Addresses\Models\Address|null $accountAddress
* @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\ActionLog\Models\ActionLog[] $actionLogs
* @property-read int|null $action_logs_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Addresses\Models\Address[] $addresses
* @property-read int|null $addresses_count
* @property-read \Illuminate\Database\Eloquent\Collection|Document[] $documents
* @property-read int|null $documents_count
* @property-read \Illuminate\Database\Eloquent\Collection|Document[] $images
* @property-read int|null $images_count
* @property-read \App\Addresses\Models\Address|null $invoiceAddress
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
* @property-read int|null $notifications_count
* @property-read \Illuminate\Database\Eloquent\Collection|Order[] $orders
* @property-read int|null $orders_count
* @property-read \App\Addresses\Models\Address|null $shippingAddress
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser query()
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereAccountAddressId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereCulture($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereFirstName($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereGender($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereInvoiceAddressId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereIsGuest($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereLastName($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereLastNamePrefix($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereRole($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereShippingAddressId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereTelephone($value)
* @method static \Illuminate\Database\Eloquent\Builder|SiteUser whereUpdatedAt($value)
* @mixin \Eloquent
*/
class SiteUser extends Authenticatable implements SiteUserInterface, DocumentableInterface, DisplayNameInterface, HasSearchableAttributesForSidebarInterface, HasThumbnailInterface, CanSetAndResetPassword
{
use Notifiable;
use HasActionLogs;
use DocumentsTrait;
use RoleTrait;
use DisplayNameTrait;
use HasThumbnailTrait;
use HasEmptyPasswordTrait;
public const USERNAME_COLUMN_NAME = 'email';
public const PASSWORD_COLUMN_NAME = 'password';
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'site_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 = ['role', 'email', 'telephone', 'password', 'first_name', 'last_name_prefix', 'last_name', 'culture', 'is_guest'];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['created_at', 'updated_at'];
/**
* 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 BelongsTo
*/
public function accountAddress(): BelongsTo {
return $this->belongsTo(get_class(app(AddressInterface::class)));
}
/**
* @return HasMany
*/
public function addresses(): HasMany
{
return $this->hasMany(get_class(app(AddressInterface::class)));
}
/**
* @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)
{
$this->notify(new SiteUserResetPasswordNotification($this, $token));
}
/**
* Send the password set notification.
*
* @param string $token
* @return void
*/
public function sendPasswordSetNotification($token)
{
$this->notify(new SiteUserSetPasswordNotification($this, $token));
}
/**
* @return BelongsTo
*/
public function shippingAddress(): BelongsTo {
return $this->belongsTo(get_class(app(AddressInterface::class)));
}
/**
* @return BelongsTo
*/
public function invoiceAddress(): BelongsTo {
return $this->belongsTo(get_class(app(AddressInterface::class)));
}
/**
* @return HasMany
*/
public function orders(): HasMany {
return $this->hasMany(Order::class);
}
/**
* @return null|string
*/
public function getDisplayName():?string
{
// If it is a new model the section name will filled by model.section.new
if($this->last_name_prefix && $this->last_name_prefix !== '') return $this->first_name . ' ' . $this->last_name_prefix . ' ' . $this->last_name;
return $this->first_name . ' ' . $this->last_name;
}
}