HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/brameda/brameda.nl/app/Komma/Users/Models/KmsUser.php
<?php

namespace App\Komma\Users\Models;

use App\Komma\Addresses\AddressableInterface;
use App\Komma\Addresses\HasAddresses;
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\Posts\Models\Post;
use App\Notifications\KmsResetPasswordNotification;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

/**
 * Class KmsUser
 *
 * @package App\Komma\Users\Models
 * @property int $id
 * @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 int $role
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereChamberOfCommerce($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCompanyCity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCompanyCountry($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCompanyHouseNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCompanyName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCompanyStreet($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCompanyVatNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCompanyVatNumberValidated($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCompanyZipCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCountry($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereFailedLoginAttempts($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereFirstName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereHouseNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereLastLoginAttempt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereLastName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereRememberToken($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereRole($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereStreet($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereTelephone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereZipCode($value)
 * @mixin \Eloquent
 * @property string $company_postal_code
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser whereCompanyPostalCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser 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\KmsUser newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Users\Models\KmsUser 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\KmsUser whereGender($value)
 */
final class KmsUser extends Authenticatable implements DocumentableInterface, DisplayNameInterface, HasThumbnailInterface, AddressableInterface, ComponentableInterface, HasSearchableAttributesForSidebarInterface {
    use Notifiable;
    use HasActionLogs;
    use HasAddresses;
    use DocumentsTrait;
    use DisplayNameTrait;
    use HasThumbnailTrait;
    use ComponentableTrait;

    public const USERNAME_COLUMN_NAME = 'email';
    public const PASSWORD_COLUMN_NAME = 'password';

    /**
     * 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', '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)
    {
        //Send kms reset mail
        $this->notify(new KmsResetPasswordNotification($this, $token));
    }

    /**
     * @return BelongsToMany
     */
    public function posts(): BelongsToMany
    {
        return $this->belongsToMany(Post::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;
    }

    /**
     * Checks if the user is at least a certain role
     *
     * @param int $role
     * @return bool
     * @see KmsUserRole
     */
    public function isAtLeast(int $role = null): bool
    {
        if(!$role) return true;
        if(!KmsUserRole::isValidItem($role)) throw new \InvalidArgumentException('The given role is not valid.');
        return ($this->role && $this->role <= $role);
    }

    /**
     * @param int $role
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public static function whereRoleIsAtLeast(int $role)
    {
        return self::query()->where('role', '<=', $role);
    }
}