Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving a datepicker value to database in laravel

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');
   }
like image 575
Sir George Avatar asked Jan 19 '17 17:01

Sir George


People also ask

How to get the date format of date in Laravel?

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');

Does Laravel Save Save date to MySQL?

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.

Is there a date mutator in Laravel?

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.

What is the best strtotime for Laravel date validation?

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.


1 Answers

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.

like image 91
Alexey Mezenin Avatar answered Oct 30 '22 08:10

Alexey Mezenin