mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Update CartModel.php
This commit is contained in:
@@ -134,7 +134,15 @@ class CartModel extends Model
|
||||
public function weight(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn () => $this->qty * $this->weight,
|
||||
get: fn (): int => {
|
||||
$sum = 0;
|
||||
|
||||
foreach (this->items as $item) {
|
||||
$sum += $this->qty * $this->weight;
|
||||
}
|
||||
|
||||
return $sum;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user