In this video we are going to learn about User Order Cancellation.
So let see how can we cancel order from user panel.
So Switch to the project
And lets open UserOrderDetailsCompoent.php class file.
Here lets create a function for Cancel the order.

public function cancelOrder()
{
$order = Order::find($this->order_id);
$order->status = \"canceled\";
$order->canceled_date = DB::raw('CURRENT_DATE');
$order->save();
session()->flash('order_message','Order has been canceled!');
}


Also import the DB


use Illuminate\\Support\\Facades\\DB;


Now go to the user-order-details-component.blade.php view file and here lets call the cancelOrder function.

<div class=\"row\">
<div class=\"col-md-12\">
@if(Session::has('order_message'))
<div class=\"alert alert-success\" role=\"alert\">{{Session::get('order_message')}}</div>
@endif
<div class=\"panel panel-default\">
<div class=\"panel-heading\">
<div class=\"row\">
<div class=\"col-md-6\">
Order Details
</div>
<div class=\"col-md-6\">
<a href=\"{{route('user.orders')}}\" class=\"btn btn-success pull-right\">My Orders</a>
@if($order->status == 'ordered')
<a href=\"#\" wire:click.prevent=\"cancelOrder\" style=\"margin-right:20px;\" class=\"btn btn-warning pull-right\">Cancel Order</a>
@endif
</div>
</div>
</div>
<div class=\"panel-body\">
<table class=\"table\">
<th>Order ID</th>
<td>{{$order->id}}</td>
<th>Order Date</th>
<td>{{$order->created_at}}</td>
<th>Status</th>
<td>{{$order->status}}</td>
@if($order->status == 'delivered')
<th>Delivery Date</th>
<td>{{$order->delivered_date}}</td>
@elseif($order->status == 'canceled')
<th>Canceled Date</th>
<td>{{$order->canceled_date}}</td>
@endif
</table>
</div>
</div>
</div>
</div>


Now its done so lets check it.
So switch to the browser and refresh the page.
Here you can see here order no 1 which order status is delivered.
If I click on details link.
Here you can see the order status delivered and delivery date.
And here cancel order link is not showing because order is already delivered.
Now lets check another order.
Now lets click on this order which is cancelled.
And here you can see the order status cancelled and cancelled date.
Now lets check this order which status is ordered, and here you can see the
Cancel order link.
If you want to cancel this order then just click here.
So Lets click, and here you can see the message order has been cancelled.
And now order status has been changed to cancelled.
So in this way you can cancel the order from user panel so that's all about User Order Cancellation.