• File: Store.php
  • Full Path: /var/www/imalipartnersapi/app/Store.php
  • Date Modified: 02/07/2023 8:01 PM
  • File size: 2.73 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace App;

use App\Bank\Payment;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use DateTimeInterface;

class Store extends Authenticatable
{
    use HasApiTokens, Notifiable;
    use LogsActivity;

    protected $guard = 'store';

    protected $fillable = [
        'session_status', 'name', 'logo', 'photo', 'nuit', 'balance', 'store_id', 'nib', 'address', 'manager', 'manager_phone_number', 'public_id', 'mobile_phone', 'account_number', 'qrcode', 'status', 'email', 'password', 'user_client_id', 'merchant_account_id', 'merchant_contract_id', 'industry_activity', 'user_id', 'firebase_token',
        'longitude', 'latitude', 'store'
    ];

    protected static $logAttributes = [
        'session_status', 'name', 'logo', 'photo', 'nuit', 'balance', 'store_id', 'nib', 'address', 'manager', 'manager_phone_number', 'public_id', 'mobile_phone', 'account_number', 'qrcode', 'status', 'email', 'password', 'user_client_id', 'merchant_account_id', 'merchant_contract_id', 'industry_activity', 'user_id', 'firebase_token',
        'longitude', 'latitude', 'store'
    ];

    protected static $logName = 'store';

    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);
    }

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

    function payments()
    {
        return $this->hasMany(Payment::class);
    }

    function paymentsGenerated()
    {
        return $this->hasMany(PaymentGeneration::class);
    }

    public function findForPassport($identifier)
    {
        return $this->orWhere('email', $identifier)->orWhere('username', $identifier)->first();
    }

    function amountGenerations()
    {
        return $this->hasMany(StoreAmountGeneration::class);
    }

//    function payment() {
//        return $this->belongsTo(Payment::class);
//    }
    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()->logOnly(["*"]);
    }
}