<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserWalletPayment extends Model
{
use HasFactory;
protected $hidden = ['id', 'unique_id'];
protected $appends = ['user_wallet_payment_id', 'user_wallet_payment_unique_id', 'requested_amount_formatted', 'paid_amount_formatted'];
protected $guarded = ['id'];
public function getUserWalletPaymentIdAttribute() {
return $this->id;
}
public function getUserWalletPaymentUniqueIdAttribute() {
return $this->unique_id;
}
public function user() {
return $this->belongsTo(User::class)->withDefault();
}
public function fromUser() {
return $this->belongsTo(User::class, 'received_from_user_id')->withDefault();
}
public function toUser() {
return $this->belongsTo(User::class, 'to_user_id')->withDefault();
}
public function getRequestedAmountFormattedAttribute() {
return formatted_amount($this->requested_amount);
}
public function getPaidAmountFormattedAttribute() {
return formatted_amount($this->paid_amount);
}
public function getStatusFormattedAttribute() {
return withdrawal_status_formatted($this->status);
}
public static function boot() {
parent::boot();
static::creating(function ($model) {
$model->attributes['unique_id'] = "UWP-".uniqid();
});
static::created(function($model) {
$model->attributes['unique_id'] = "UWP-".$model->attributes['id']."-".uniqid();
$model->save();
});
}
}