I am using Laravel 5.4 and I have Check Out button in my table. I want when I click that button, it will update check out time in the database and update my table. I am trying to use ajax, but it is not working, but sometimes it is working too but not reload the table so I need to refresh the page manualy.
Here is my button code:
<a type="button" name="checkout_btn" id="checkout_btn" data-id=" {{ $Data->VST_ID }}" class="btn btn-primary">Check Out</a>
This is my ajax code:
$('#checkout_btn').click(function addseries(e){
var VST_ID = $(e.currentTarget).attr('data-id');
alert("dfads");
$.ajax({
type: "GET",
url: 'visitor/checkout',
data: "VST_ID="+VST_ID,
success: function(data) {
console.log(data);
}
});
});
Here is my controller code:
public function Checkout(Request $request)
{
$visitor = Visitor::where("VST_ID",$request['VST_ID'])->first();
$visitor->VST_CHECKOUT = date('Y-m-d H:i:s');
$visitor->UPDATED_AT = date('Y-m-d H:i:s');
$visitor->UPDATED_BY = 'User';
$visitor->save();
return redirect()->route('Visitor.VList')->with('message','The Visitor has been Checked Out !');
}