0

How to checkin and checkout time data save in MySQL using jquery?

.checkin button click to start live time .checkout button click then stop time .And both are save data in MYSQL database...

Mukund Bharti
  • 251
  • 4
  • 19

2 Answers2

1

you can make an Ajax call to your server, and if you are using Carbon date library in your Laravel app, then use Carbon::now() to log the current checkin and checkout time.

$("button").click(function(){
  $.ajax({url: "user/checkin", success: function(result){
    // to do
  }});
});

$("button").click(function(){
  $.ajax({url: "user/checkout", success: function(result){
    // to do
  }});
});

then at the controller function

public function checkin(Request $request) {
  $user = $request->user();

  $user->checkin_in = \Carbon::now();
  $user->save();

}
sunder s
  • 86
  • 5
0
new Date().toISOString().slice(0, 19).replace('T', ' ');

Copied from here: Convert JS date time to MySQL datetime