I tried to save some time in my database in time format for some time, for example 10:00:00.
I want to just pick a time from timepickerand save data(time)to timeformat.
Here is what I did:
I used timepickerbecause it receives data in a format 10:52 AM.
I used access methods to save time as follows:
public function setRTimeAttribute($value)
{
$this->attributes['r_time'] = date('h:i:A', strtotime($value));
}
My post controller if necessary:
public function postSessionReservation(Request $request,$profile_slug)
{
$restaurant = Restaurant::where('slug_profile', $profile_slug)->select('name','ar_name','slug_profile','id')->firstOrFail();
$this->validate($request,[
'no_of_seats'=>'required',
'r_date'=>'required',
'r_time'=>'required',
'restaurant_id'=>'required',
]);
$data = [
'no_of_seats'=>$request->no_of_seats,
'r_date'=>$request->r_date,
'r_time'=>$request->r_time,
'restaurant_id'=>$request->restaurant_id
];
$minutes = 1;
Session::put('reservation',json_encode($data),$minutes);
return redirect($restaurant->slug_profile.'/complete-reservation');
}
But it saves time like 12:00:00every time.
I do not know how it is 12:00:00generated whenever I save time. I tried a lot, but could not understand.
Hope you guys help me solve this problem.
Thanks in advance.