File: D:/HostingSpaces/SBogers10/sdo-schoonmaak.komma.pro/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\Shop\Orders\Models\Order;
use App\Notifications\ResetPasswordNotification;
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 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 $country
* @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\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
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereChamberOfCommerce($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCity($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 whereCountry($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 whereHouseNumber($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 whereStreet($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 whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereUsername($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereZipCode($value)
* @mixin \Eloquent
* @property string $company_postal_code
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User whereCompanyPostalCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\User wherePostalCode($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Shop\Orders\Models\Order[] $orders
* @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'];
public function getDates()
{
return array('created_at', 'updated_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)
{
$this->notify(new ResetPasswordNotification($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::get('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();
}
public function __get($key)
{
if($key == "title") {
return $this->first_name." ".$this->last_name;
}
return parent::__get($key);
}
}