hasMany(SaleItem::class); } public function customer() { return $this->belongsTo(Customer::class); } public function formatHumanCreatedAt(): Attribute { return Attribute::make(get: function () { return Carbon::parse($this->created_at)->locale('id')->translatedFormat('d F Y'); }); } public function formatCreatedAt(): Attribute { return Attribute::make(get: function () { return Carbon::parse($this->created_at)->locale('id')->translatedFormat('d F Y H:i:s'); }); } public function displayAmount(): Attribute { return Attribute::make(get: function () { return 'Rp' . number_format($this->amount, 0, ',', '.'); }); } public function create_notification() { Notification::create([ 'entity_type' => User::class, 'description' => $this->customer->fullname . ' melakukan pembelian ' . $this->items()->count() . ' voucher sebesar ' . $this->display_amount, ]); Notification::create([ 'entity_id' => auth()->id(), 'description' => 'Transaksi pembelian anda #' . $this->code . ' sebesar ' . $this->display_amount . ' berhasil', ]); } }