File: D:/HostingSpaces/SBogers10/somerenslust.komma.pro/app/KommaApp/Users/Models/User.php
<?php
namespace App\KommaApp\Users\Models;
use App\KommaApp\Images\Models\Image;
use App\Notifications\ResetPasswordNotification;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable {
use Notifiable;
// 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);
}
public function getAuthIdentifierName()
{
return $this->getKeyName();
}
public function canUseKms()
{
if($this->role->isAtLeast(Role::Schema)){
return true;
} else{
return abort(401, 'This action is unauthorized.');
}
}
public function __get($key)
{
if($key == "title") {
return $this->first_name." ".$this->last_name;
}
return parent::__get($key);
}
}