In this video we are going to learn about Add SaveForLater Option on Cart Page.
So let see how can we add SaveForLater Option on Cart Page.
Switch to the project and lets open the CartComponent.php class file.
Inside this file lets create a function for Switch Product to SaveForLater.


public function switchToSaveForLater($rowId)
{
$item = Cart::instance('cart')->get($rowId);
Cart::instance('cart')->remove($rowId);
Cart::instance('saveForLater')->add($item->id,$item->name,1,$item->price)->associate('App\\Models\\Product');
$this->emitTo('cart-count-component','refreshComponent');
session()->flash('success_message','Item has been saved for later');
}


Now lets open cart-component.blade.php view file lets add a link for SaveForLater as following.


<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>
</div>
<p class=\"text-center\"><a href=\"#\" wire:click.prevent=\"switchToSaveForLater('{{$item->rowId}}')\">Save For Later</a></p>


Now lets display all items which are saved for later. so for that lets copy this cart wrap div.
And just copy and paste after this summary div and make changes as following.

<div class=\"wrap-iten-in-cart\">
<h3 class=\"title-box\" style=\"border-bottom: 1px solid; padding-bottom:15px;\">{{Cart::instance('saveForLater')->count()}} item(s) Saved For Later</h3>
@if(Session::has('s_success_message'))
<div class=\"alert alert-success\">
<strong>Success</strong> {{Session::get('s_success_message')}}
</div>
@endif
@if(Cart::instance('saveForLater')->count() > 0)
<h3 class=\"box-title\">Products Name</h3>
<ul class=\"products-cart\">
@foreach (Cart::instance('saveForLater')->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>
<div class=\"product-name\">
<a class=\"link-to-product\" href=\"{{route('product.details',['slug'=>$item->model->slug])}}\">{{$item->model->name}}</a>
</div>
<div class=\"price-field produtc-price\"><p class=\"price\">${{$item->model->regular_price}}</p></div>
<div class=\"quantity\">
<p class=\"text-center\"><a href=\"#\" wire:click.prevent=\"moveToCart('{{$item->rowId}}')\">Move To Cart</a></p>
</div>
<div class=\"delete\">
<a href=\"#\" wire:click.prevent=\"deleteFromSaveForLater('{{$item->rowId}}')\" class=\"btn btn-delete\" title=\"\">
<span>Delete from save for later</span>
<i class=\"fa fa-times-circle\" aria-hidden=\"true\"></i>
</a>
</div>
</li>
@endforeach
</ul>
@else
<p>No item saved for later</p>
@endif
</div>


Now lets create function for moving product to the cart
So go to the CartComponent class file and lets create a function here
Also create a function for delete fromSaveForLater


public function moveToCart($rowId)
{
$item = Cart::instance('saveForLater')->get($rowId);
Cart::instance('saveForLater')->remove($rowId);
Cart::instance('cart')->add($item->id,$item->name,1,$item->price)->associate('App\\Models\\Product');
$this->emitTo('cart-count-component','refreshComponent');
session()->flash('s_success_message','Item has been moved to cart');
}

public function deleteFromSaveForLater($rowId)
{
Cart::instance('saveForLater')->remove($rowId);
session()->flash('s_success_message','Item has been removed from save for later');
}


Now its done so lets check it so switch to the browser and refresh the page.
Now go to the shop page and lets add product to the cart.
Add one more product to the cart.
Now you can see the save for later link.
Now click on it.
Now you can see here product has been moved to save for later.
And here you can see the no of product in saved for later.
Now for moving the product from save for later to cart lets click on this link.
You can see here product has been move into cart.
alright Now lets remove this product from save for later so just click on this cross icon.
And you can product has been removed from save for later.
So in this way you can use save for later option on Cart Page.