-membuat relasi polimorfirk -membuat beberapa trait untuk kebutuhan crud -dan lainnya tentang implementasi fitur ini
20 lines
418 B
PHP
20 lines
418 B
PHP
<?php
|
|
|
|
namespace App\Traits\Purchase;
|
|
|
|
use App\Models\PurchaseItem;
|
|
|
|
trait WithDeleteItem
|
|
{
|
|
public function deleteItem(PurchaseItem $item)
|
|
{
|
|
$this->form->cartItems = $this->form->cartItems->reject(fn ($i) => $i->id === $item->id);
|
|
|
|
$item->delete();
|
|
|
|
$this->form->total = currency($this->form->cartItems->sum('total_price'), '');
|
|
|
|
$this->toast('Item berhasil dihapus.');
|
|
}
|
|
}
|