feat: add HasCart trait and ShareCartWithInertia

This commit is contained in:
Joel Male
2026-05-27 21:38:44 +10:00
parent a485bfb6f0
commit 0efd4378a8
4 changed files with 225 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Wearepixel\Cart\Concerns;
use Wearepixel\Cart\Cart;
class ShareCartWithInertia
{
public static function data(?Cart $cart = null): array
{
$cart ??= app('cart');
return [
'items' => $cart->getContent()->toArray(),
'subtotal' => (float) $cart->getSubTotal(false),
'total' => (float) $cart->getTotal(),
'count' => (int) $cart->getTotalQuantity(),
];
}
}