I have this input in my form... I need to store the date picked from it, but I get a null value when I submit
<script type="text/javascript">
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<input type="text" required="" placeholder="When are You Coming Back" name="datepicker2" id="datepicker2" value="" name="datepicker2" class="txt">
am I missing something?? when I submit I don't get any values in the database, I am using laravel5
class LeaveController extends Controller
{
public function ApplyLeave(Request $request)
{
Auth::user()->sent()->create([
'tel' => $request->tel,
'email' => $request->email,
'start' => $request->datepicker,
'end' => $request->datepicker1,
'supervisor' => $request->supervisor,
'department' => $request->department,
'name' => $request->name,
'adress' => $request->adress,
]);
return view('home');
}
Laravel's datevalidation expects a value that strtotime can handle. If you're using an ambiguous date format, use createFromFormatto parse it, then formatto spit it out in a more standard format. $date = DateTime::createFromFormat('d-m-Y H:i:s', Input::get('plannedTime')); $usableDate = $date->format('Y-m-d H:i:s');
Laravel: saving date to MySQL Ask Question Asked6 years, 9 months ago Active6 years, 9 months ago Viewed30k times 6 1 In my controller, when I createan event, it saves perfectly fine.
If you don't want to use laravels date mutator, you can use your own something like this: Hope this helps. Show activity on this post. Laravel makes use of carbon and makes tasks like this an absolute walk in the park.
PHP's strtotimedoes its best, but 04-05-2015 00:00:00could be either April 5 or May 4, depending where you live. As an example, on my install, strtotime('04-13-2014 00:00:00')fails (which'll get converted to 0, which'll get converted to 1970-01-01). Laravel's datevalidation expects a value that strtotime can handle.
Parsing dates should work:
'start' => Carbon::parse($request->datepicker),
'end' => Carbon::parse($request->datepicker1),
Also, it's a good idea to put start
and end
to the $dates
array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With