Viewing File: /home/ubuntu/vedadeals-backend-base/app/Models/UserBillingAccount.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class UserBillingAccount extends Model
{
    use HasFactory;

    protected $hidden = ['id', 'unique_id'];

    protected $appends = ['user_billing_account_id', 'user_billing_account_unique_id', 'user_billing_account_name'];

    protected $guarded = ['id'];

    public function getUserBillingAccountIdAttribute() { 

        return $this->id;
    }

    public function getUserBillingAccountUniqueIdAttribute() {

        return $this->unique_id;
    }

    public function user() {

        return $this->belongsTo(User::class)->withDefault();
    }

    public function getUserBillingAccountNameAttribute() {

        $first_name = $this->first_name ? : ''; $last_name = $this->last_name ? : '';

        return $first_name.' '.$last_name;
    }

    public static function boot() {

        parent::boot();

        static::creating(function ($model) {

            $model->attributes['unique_id'] = "UBA-".uniqid();

        });

        static::created(function($model) {

            $model->attributes['unique_id'] = "UBA-".$model->attributes['id']."-".uniqid();
            
            $model->save();
        
        });
    }
}
Back to Directory File Manager