mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
feat: add HasCart trait and ShareCartWithInertia
This commit is contained in:
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user