-
app/Services/CartService.php
Open in GitHubuse App\Cart; use Illuminate\Support\Facades\Cookie; class CartService { protected $cookieName; protected $cookieExpiration; public function __construct() { $this->cookieName = config('cart.cookie.name'); $this->cookieExpiration = config('cart.cookie.expiration'); } public function getFromCookie() { $cartId = Cookie::get($this->cookieName); return Cart::find($cartId); } // }
-
app/Http/Controllers/CartController.php
Open in GitHubuse App\Services\CartService; class CartController extends Controller { public $cartService; public function __construct(CartService $cartService) { $this->cartService = $cartService; } public function index() { $cart = $this->cartService->getFromCookie(); return view('carts.index')->with([ 'cart' => $cart, ]); } }