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

<?php

namespace App\Models;

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

class OrderPayment extends Model
{
    use HasFactory;

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

    protected $appends = ['order_payment_id', 'order_payment_unique_id'];

    protected $guarded = ['id'];

    public function getOrderPaymentIdAttribute() { 

        return $this->id;
    }

    public function getOrderPaymentUniqueIdAttribute() {

        return $this->unique_id;
    }

    public function scopeApproved($query) {

        return $query->where('status', APPROVED);
    }

    public function order() {

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

    public function user() {

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

    public static function boot() {

        parent::boot();

        static::creating(function ($model) {

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

        });

        static::created(function($model) {

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

            $model->save();
        
        }); 

        static::updating(function ($model) {
   
        });

        static::deleting(function ($model) {
            
        });
    }
}
Back to Directory File Manager