100 lines
2.4 KiB
PHP
100 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\OLDLMS;
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable;
|
|
|
|
const CREATED_AT = 'dCreateOn';
|
|
const UPDATED_AT = 'dUpdateOn';
|
|
const DELETED_AT = 'dDeleteOn';
|
|
|
|
protected $connection = 'oldlms';
|
|
|
|
protected $table = 'tm_users';
|
|
|
|
protected $appends = [
|
|
'full_name',
|
|
];
|
|
|
|
protected $primaryKey = 'nID';
|
|
protected $fillable = [
|
|
'nID',
|
|
'sFirstName',
|
|
'sLastName',
|
|
'sPhone',
|
|
'sEmail',
|
|
'nIDHubunganKeluarga',
|
|
'dUpdateOn',
|
|
'sIPAddress',
|
|
'fcm_token',
|
|
];
|
|
|
|
protected function fullName(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: function ($value) {
|
|
$names = [];
|
|
if (!empty($this->sFirstName)) {
|
|
array_push($names, $this->sFirstName);
|
|
}
|
|
if (!empty($this->sLastName)) {
|
|
array_push($names, $this->sLastName);
|
|
}
|
|
|
|
return implode(' ', $names);
|
|
}
|
|
);
|
|
}
|
|
|
|
public function detail()
|
|
{
|
|
return $this->hasOne(UserDetail::class, 'nIDUser', 'nID');
|
|
}
|
|
|
|
public function relation()
|
|
{
|
|
return $this->hasOne(Relationship::class, 'nID', 'nIDHubunganKeluarga');
|
|
}
|
|
|
|
public function insurances()
|
|
{
|
|
return $this->hasMany(UserInsurance::class, 'nIDUser', 'nID');
|
|
}
|
|
|
|
public function notificationTokens()
|
|
{
|
|
return $this->morphMany(NotificationToken::class, 'notifiabletoken');
|
|
}
|
|
|
|
public function routeNotificationForFcm()
|
|
{
|
|
return $this->notificationTokens()->pluck('token')->toArray();
|
|
}
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function ($user) {
|
|
$user->sIPAddress = request()->ip();
|
|
});
|
|
|
|
static::updating(function ($user) {
|
|
$user->sIPAddress = request()->ip();
|
|
});
|
|
}
|
|
}
|