Files
streamline-emr/docker/_streamline-src/app/Models/User.php
T

93 lines
2.6 KiB
PHP
Executable File

<?php
namespace Streamline\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Auth;
use Spatie\Permission\Traits\HasRoles;
use OwenIt\Auditing\Contracts\Auditable;
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\SoftDeletes;
//use Laravel\Passport\HasApiTokens;
class User extends Authenticatable implements Auditable {
use Notifiable;
use HasRoles;
use \OwenIt\Auditing\Auditable;
use SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'first_name', 'last_name', 'username', 'phone', 'position_id', 'email', 'photo', 'council_registration', 'willing_to_donate', 'last_donation_date', 'council_id', 'registration_number', 'expiry_date', 'password',
'pin', 'blood_group_id', 'created_by', 'updated_by', 'last_seen'
];
public $timestamps = true;
protected $rememberTokenName = false;
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token'
];
protected $casts = [
'expiry_date' => 'datetime',
'last_donation_date' => 'datetime'
];
/*
* Below are some mutators
*/
private string $first_name;
private string $last_name;
public function setExpiryDateAttribute($expiry_date): void
{
$this->attributes['expiry_date'] = empty($expiry_date) ? NULL : Carbon::createFromFormat('d/m/Y', $expiry_date)->format('Y-m-d');
}
public function setLastDonationDateAttribute($last_donation_date): void
{
$this->attributes['last_donation_date'] = empty($last_donation_date) ? NULL : Carbon::createFromFormat('d/m/Y', $last_donation_date)->format('Y-m-d');
}
/*
* Accessors
*/
public function getExpiryDateAttribute($expiry_date): string
{
return $expiry_date == NULL ? '' : Carbon::createFromFormat('Y-m-d', $expiry_date)->format('d/m/Y');
}
public function getLastDonationDateAttribute($last_donation_date): string
{
//$last_donation_date == NULL ? '' : Carbon::createFromFormat('Y-m-d', $last_donation_date)->format('d/m/Y');
return '';
}
public static function resolveId() {
return Auth::check() ? Auth::user()->getAuthIdentifier() : null;
}
public function passwordSecurity()
{
return $this->hasOne('Streamline\Models\PasswordSecurity');
}
public function getFullNameAttribute(): string
{
return $this->first_name . ' ' . $this->last_name;
}
}