<?php
namespace App;
use App\Bank\HistoryPayment;
use App\Bank\Payment;
use App\Imali\ImaliAccount;
use App\Imali\RechargeImaliAccount;
use App\Imali\Transfer;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Laravel\Passport\HasApiTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
use LogsActivity;
protected static $logAttributes = [
'name',
'bi',
'email',
'password',
'phone',
'level',
'user_id',
'photo',
'points',
'status',
'birthday',
'account_number',
'balance',
'is_Active',
'pin',
'text',
'user.name',
'firebase_token',
'phone_reference',
'country_code',
'balance_visibility',
'terminalCompanyName',
'terminalChannel',
'terminalID',
'client_id',
'document_id',
'user_update_info_status',
'update_info_status'
];
protected $fillable = [
'name',
'bi',
'email',
'password',
'phone',
'level',
'user_id',
'photo',
'points',
'status',
'birthday',
'account_number',
'balance',
'is_Active',
'pin',
'text',
'firebase_token',
'phone_reference',
'country_code',
'balance_visibility',
'terminalCompanyName',
'terminalChannel',
'terminalID',
'client_id',
'document_id',
'user_update_info_status',
'update_info_status'
];
protected $logAttribute = [
'name',
'bi',
'email',
'password',
'phone',
'level',
'user_id',
'photo',
'points',
'status',
'birthday',
'account_number',
'balance',
'is_Active',
'text',
'user.name',
'firebase_token',
'phone_reference',
'country_code',
'balance_visibility',
'terminalCompanyName',
'terminalChannel',
'terminalID',
'client_id',
'document_id',
'user_update_info_status',
'update_info_status'
];
public function getDescriptionForEvent(string $eventName): string
{
return "This model has been {$eventName}";
}
public function user()
{
return $this->belongsTo(User::class);
}
protected static $logName = 'user';
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token', 'pin',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function setNameAttribute($value)
{
return $this->attributes['name'] = ucwords(strtolower($value));
}
public function setEmailAttribute($value)
{
$this->attributes['email'] = strtolower($value);
}
public function setBiAttribute($value)
{
$this->attributes['bi'] = strtoupper($value);
}
function bankAccounts()
{
return $this->hasMany(BankAccount::class);
}
function payments()
{
return $this->hasMany(Payment::class);
}
function paymentsGenerated()
{
return $this->hasMany(PaymentGeneration::class);
}
function paymentsHistory()
{
return $this->hasMany(HistoryPayment::class);
}
function imaliAccount()
{
return $this->hasOne(ImaliAccount::class);
}
function documents()
{
return $this->hasMany(UserDocument::class);
}
function transferencias()
{
return $this->hasMany(Transfer::class);
}
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('d-m-Y H:i:s');
}
function transactionHistories()
{
return $this->hasMany(TransactionHistory::class);
}
function transferHistories()
{
return $this->hasMany(TransferHistory::class);
}
function voucherHistory()
{
return $this->hasMany(VoucherHistory::class, 'user_id');
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()->logOnly($this->logAttribute);
}
}