In this video we are going to learn about Cart Settings for Checkout.
So let see how can we do cart settings for checkout.
Switch to project and lets open the CartComponent.php Class file.
Now inside this file lets create a function for checkout and add the following code.

public function checkout()
return redirect()->route('checkout');
return redirect()->route('login');

Also import the Auth so write the following code before the class.

use Illuminate\\Support\\Facades\\Auth;

Now go to the cart-component.blade.php file.
And inside this lets find the checkout link
And here inside this anchor tag lets call this checkout function.
So write here.

<a class=\"btn btn-checkout\" href=\"#\" wire:click.prevent=\"checkout\">Check out</a>

When if cart is empty then just hide this cart summary and checkout link.
So for that make changes in code as following.

@if(Cart::instance('cart')->count() > 0)
<div class=\"wrap-iten-in-cart\">
<div class=\"alert alert-success\">
<strong>Success</strong> {{Session::get('success_message')}}
@if(Cart::instance('cart')->count() > 0)
<h3 class=\"box-title\">Products Name</h3>
<ul class=\"products-cart\">
@foreach (Cart::instance('cart')->content() as $item)
<li class=\"pr-cart-item\">
<div class=\"product-image\">
<figure><img src=\"{{ ('assets/images/products') }}/{{$item->model->image}}\" alt=\"{{$item->model->name}}\"></figure>
<div class=\"product-name\">
<a class=\"link-to-product\" href=\"{{route('product.details',['slug'=>$item->model->slug])}}\">{{$item->model->name}}</a>
<div class=\"price-field produtc-price\"><p class=\"price\">${{$item->model->regular_price}}</p></div>
<div class=\"quantity\">
<div class=\"quantity-input\">
<input type=\"text\" name=\"product-quatity\" value=\"{{$item->qty}}\" data-max=\"120\" pattern=\"[0-9]*\" >
<a class=\"btn btn-increase\" href=\"#\" wire:click.prevent=\"increaseQuantity('{{$item->rowId}}')\"></a>
<a class=\"btn btn-reduce\" href=\"#\" wire:click.prevent=\"decreaseQuantity('{{$item->rowId}}')\"></a>
<p class=\"text-center\"><a href=\"#\" wire:click.prevent=\"switchToSaveForLater('{{$item->rowId}}')\">Save For Later</a></p>
<div class=\"price-field sub-total\"><p class=\"price\">${{$item->subtotal}}</p></div>

<div class=\"delete\">
<a href=\"#\" wire:click.prevent=\"destroy('{{$item->rowId}}')\" class=\"btn btn-delete\" title=\"\">
<span>Delete from your cart</span>
<i class=\"fa fa-times-circle\" aria-hidden=\"true\"></i>
<p>No item in cart</p>

<div class=\"summary\">
<div class=\"order-summary\">
<h4 class=\"title-box\">Order Summary</h4>
<p class=\"summary-info\"><span class=\"title\">Subtotal</span><b class=\"index\">${{Cart::instance('cart')->subtotal()}}</b></p>
<p class=\"summary-info\"><span class=\"title\">Discount ({{Session::get('coupon')['code']}}) <a href=\"#\" wire:click.prevent= \"removeCoupon\"><i class=\"fa fa-times text-danger\"></i></a></span></span><b class=\"index\"> -${{number_format($discount,2)}}</b></p>
<p class=\"summary-info\"><span class=\"title\">Subtotal with Discount</span></span><b class=\"index\">${{number_format($subtotalAfterDiscount,2)}}</b></p>
<p class=\"summary-info\"><span class=\"title\">Tax ({{config('')}}%)</span></span><b class=\"index\">${{number_format($taxAfterDiscount,2)}}</b></p>
<p class=\"summary-info total-info \"><span class=\"title\">Total</span><b class=\"index\">${{number_format($totalAfterDiscount,2)}}</b></p>
<p class=\"summary-info\"><span class=\"title\">Tax</span><b class=\"index\">${{Cart::instance('cart')->tax()}}</b></p>
<p class=\"summary-info\"><span class=\"title\">Shipping</span><b class=\"index\">Free Shipping</b></p>
<p class=\"summary-info total-info \"><span class=\"title\">Total</span><b class=\"index\">${{Cart::instance('cart')->total()}}</b></p>
<div class=\"checkout-info\">
<label class=\"checkbox-field\">
<input class=\"frm-input \" name=\"have-code\" id=\"have-code\" value=\"1\" type=\"checkbox\" wire:model=\"haveCouponCode\"><span>I have coupon code</span>
@if($haveCouponCode == 1)
<div class=\"summary-item\">
<form wire:submit.prevent=\"applyCouponCode\">
<h4 class=\"title-box\">Coupon Code</h4>
<div class=\"alert alert-danger\" role=\"danger\">{{Session::get('coupon_message')}}</div>
<p class=\"row-in-form\">
<label for=\"coupon-code\">Enter your coupon code:</label>
<input type=\"text\" name=\"coupon-code\" wire:model=\"couponCode\" />
<button type=\"submit\" class=\"btn btn-small\">Apply</button>
<a class=\"btn btn-checkout\" href=\"#\" wire:click.prevent=\"checkout\">Check out</a>
<a class=\"link-to-shop\" href=\"shop.html\">Continue Shopping<i class=\"fa fa-arrow-circle-right\" aria-hidden=\"true\"></i></a>
<div class=\"update-clear\">
<a class=\"btn btn-clear\" href=\"#\" wire:click.prevent=\"destroyAll()\">Clear Shopping Cart</a>
<a class=\"btn btn-update\" href=\"#\">Update Shopping Cart</a>
<div class=\"text-center\" style=\"padding:30px 0;\">
<h1>Your cart is empty!</h1>
<p>Add items to it now</p>
<a href=\"/shop\" class=\"btn btn-success\">Shop Now</a>

Now go to the CartComponent.php class file and here lets create a function for callculate the discount.
First of all check if coupon is applied then put discounted price into session else put normal price into the session.

public function setAmountForCheckout()
if(!Cart::instance('cart')->count() > 0)

'discount' => $this->discount,
'subtotal' => $this->subtotalAfterDiscount,
'tax' => $this->taxAfterDiscount,
'total' => $this->totalAfterDiscount
'discount' => 0,
'subtotal' => Cart::instance('cart')->subtotal(),
'tax' => Cart::instance('cart')->tax(),
'total' => Cart::instance('cart')->total()

Now lets call this function inside the render method.


Alright now lets check it.
So switch to the browser and refresh the page.
Now here the cart summary and checkout link is not showing.
Because this time the cart is empty.
Now lets add product to cart.
So click on this link and lets add this product to cart.
Now here you can see the cart item, cart summary and this checkout link.
Alright, This time no user is logged in.
So if I click on checkout link, it must redirects me on login page.
So lets click on this checkout link.
And now you can see here It sent me to the login page.
Now lets enter the user email id and password now click on login.
Now user is logged in.
Now go to cart page and click on checkout.
And this time you can see here the checkout page.
So in this way you can do Cart Settings for Checkout.