mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-24 07:55:35 +00:00
Update CartModel.php
This commit is contained in:
@@ -134,7 +134,15 @@ class CartModel extends Model
|
|||||||
public function weight(): Attribute
|
public function weight(): Attribute
|
||||||
{
|
{
|
||||||
return new 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