Viewing File: /home/ubuntu/vedadeals-backend-base/app/Models/UserWithdrawal.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserWithdrawal extends Model
{
use HasFactory;
protected $hidden = ['id', 'unique_id'];
protected $appends = ['user_withdrawal_id', 'user_withdrawal_unique_id', 'requested_amount_formatted', 'paid_amount_formatted', 'status_formatted', 'user_billing_account_name'];
protected $guarded = [];
public function getUserWithdrawalIdAttribute() {
return $this->id;
}
public function getUserWithdrawalUniqueIdAttribute() {
return $this->unique_id;
}
public function getRequestedAmountFormattedAttribute() {
return formatted_amount($this->requested_amount);
}
public function getPaidAmountFormattedAttribute() {
$amount_type = $this->userWalletPayment->amount_type ?? AMOUNT_TYPE_MINUS;
unset($this->userWalletPayment);
return formatted_wallet_transaction_amount($this->paid_amount, $amount_type);
}
public function getStatusFormattedAttribute() {
return withdrawal_status_formatted($this->status);
}
public function user() {
return $this->belongsTo(User::class)->withDefault();
}
public function userWalletPayment() {
return $this->belongsTo(UserWalletPayment::class)->withDefault();
}
public function userBillingAccount() {
return $this->belongsTo(UserBillingAccount::class)->withDefault();
}
public function getUserBillingAccountNameAttribute() {
$user_billing_account_name = $this->userBillingAccount->user_billing_account_name ?? '';
unset($this->userBillingAccount);
return $user_billing_account_name;
}
public static function boot() {
parent::boot();
static::creating(function ($model) {
$model->attributes['unique_id'] = "U-W".uniqid();
});
static::created(function($model) {
$model->attributes['unique_id'] = "U-W".$model->attributes['id']."-".uniqid();
$model->save();
});
}
}
Back to Directory
File Manager