• File: Admin.php
  • Full Path: /var/www/imaliapitest/app/Admin.php
  • Date Modified: 05/19/2025 4:29 PM
  • File size: 2.72 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace App;

use App\Bank\HistoryPayment;
use App\Bank\Payment;
use App\Imali\ImaliAccount;
use App\Imali\Transfer;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;
use DateTimeInterface;
use Spatie\Activitylog\LogOptions;

class Admin extends Authenticatable
{
    use HasApiTokens, Notifiable;

    protected $guard = 'admin';

    protected $fillable = [
        'name',
        'last_name',
        'bi',
        'email',
        'password',
        'phone',
        'level',
        'user_id',
        'photo',
        'points',
        'status',
        'birthday',
        'account_number',
        'balance',
        'is_Active',
        'pin',
        'text',
        'profile',
        'session_status'
    ];
    protected static $logAttributes = [
        'name',
        'bi',
        'email',
        'password',
        'phone',
        'level',
        'user_id',
        'photo',
        'points',
        'status',
        'birthday',
        'account_number',
        'balance',
        'is_Active',
        'pin',
        'text',
        'session_status'
    ];

    protected static $logName = 'admin';

    public function getDescriptionForEvent(string $eventName): string
    {
        return "This model has been {$eventName}";
    }
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];


    public function setNameAttribute($value)
    {
        $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 paymentsHistory()
    {
        return $this->hasMany(HistoryPayment::class);
    }

    function imaliAccount()
    {
        return $this->hasOne(ImaliAccount::class);
    }

    function transferencias()
    {
        return $this->hasMany(Transfer::class);
    }

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('d-m-Y H:i:s');
    }

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()->logOnly(['*']);
    }
}