batch_id == '') { $voucher->batch_id = Str::ulid(); } if ($voucher->price == '') { $price = $voucher->display_price; if ($voucher->discount > 0) { $price = $voucher->display_price - round($voucher->display_price * ($voucher->discount / 100), 2); } $voucher->price = $price; } }); static::updating(function (Voucher $voucher) { $price = $voucher->display_price; if ($voucher->discount > 0) { $price = $voucher->display_price - round($voucher->display_price * ($voucher->discount / 100), 2); } $voucher->price = $price; }); } public function displayQuota(): Attribute { return Attribute::make(get: function () { return round($this->quota / (1024 * 1024 * 1024), 2) . ' GB'; }); } public function displayExpired(): Attribute { return Attribute::make(get: function () { return $this->expired . ' ' . $this->expired_unit; }); } public function location() { return $this->belongsTo(Location::class)->withTrashed(); } public function shuffle_unsold() { $voucher = Voucher::where([ ['is_sold', '=', self::UNSOLD], ['batch_id', '=', $this->batch_id] ])->first(); return $voucher; } }