title: Laravel - How to retain the datepicker filter value after submit
body: <p>In my Laravel-5.8, I use JQuery-UI datepicker to filter the table:</p>
  <p>Controller:</p>
  <pre class="lang-php prettyprint-override"><code>    public function leaveReport(Request $request)
      {
          if (! Gate::allows('hr_leave_report_access')) {
              return abort(401);
          }
      try{
          $userCompany = Auth::user()-&gt;company_id;
          $method = $request-&gt;method();
  
          if ($request-&gt;isMethod('post'))
          {
              $from = Carbon::createFromFormat('d-m-Y', $request-&gt;input('from'));
              $to = Carbon::createFromFormat('d-m-Y', $request-&gt;input('to'));
              if ($request-&gt;has('search'))
              {
                  // select search
                  $searchReports = DB::table('hr_leave_requests AS lr')
                          -&gt;join('hr_leave_types AS lt', 'lr.leave_type_id', '=', 'lt.id')
                          -&gt;join('hr_employees AS em', 'lr.employee_id', '=', 'em.id')
                          -&gt;where('lr.leave_status', 4)
                          -&gt;where('lr.company_id', $userCompany)
                          -&gt;whereBetween('lr.commencement_date', [$from, $to])
                          -&gt;select('em.employee_code',DB::raw(&quot;CONCAT(em.first_name,' ',em.last_name) as full_name&quot;),'lr.commencement_date','lr.resumption_date','lr.no_of_days','lt.leave_type_name')
                          -&gt;get();
                  return view('reports.leaveReport',[
                                              'searchReports' =&gt; $searchReports,
                                              'from' =&gt; $from,
                                              'to' =&gt; $to
                                              ]);
              }
              elseif ($request-&gt;has('exportPDF'))
              {
                  // select PDF
                  $pdfReports = DB::table('hr_leave_requests AS lr')
                      -&gt;join('hr_leave_types AS lt', 'lr.leave_type_id', '=', 'lt.id')
                      -&gt;join('hr_employees AS em', 'lr.employee_id', '=', 'em.id')
                      -&gt;where('lr.leave_status', 4)
                      -&gt;where('lr.company_id', $userCompany)
                      -&gt;whereBetween('lr.commencement_date', [$from, $to])
                      -&gt;select('em.employee_code',DB::raw(&quot;CONCAT(em.first_name,' ',em.last_name) as full_name&quot;),'lr.commencement_date','lr.resumption_date','lr.no_of_days','lt.leave_type_name')
                      -&gt;get();
                  $pdf = PDF::loadView('reports.leaveReportPdf', ['pdfReports' =&gt; $pdfReports])-&gt;setPaper('a4', 'landscape');
                  return $pdf-&gt;download('HR-LeaveTakenByDate-Report.pdf');
              }
          }
              elseif($request-&gt;has('exportExcel'))
              {
                  // select Excel
                  return Excel::download(new LeaveExport($from, $to), 'hr-leave-reports.xlsx');
      //            {
              }
          else
          {
              //select all
              $searchReports = DB::table('hr_leave_requests AS lr')
                      -&gt;join('hr_leave_types AS lt', 'lr.leave_type_id', '=', 'lt.id')
                      -&gt;join('hr_employees AS em', 'lr.employee_id', '=', 'em.id')
                      -&gt;where('lr.leave_status', 4)
                      -&gt;where('lr.company_id', $userCompany)
                      -&gt;whereYear('lr.commencement_date', date('Y'))
                      -&gt;select('em.employee_code',DB::raw(&quot;CONCAT(em.first_name,' ',em.last_name) as full_name&quot;),'lr.commencement_date','lr.resumption_date','lr.no_of_days','lt.leave_type_name')
                      -&gt;get();
                   //   dd($searchReports-&gt;toSql());
  
              return view('reports.leaveReport',['searchReports' =&gt; $searchReports]);
          }
  
          } catch (Exception $exception) {
              Log::error($exception);
  
              Session::flash('error', 'Action failed! Please try again');
              return back();
          }
      }
  </code></pre>
  <p>This is the view blade:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt;
    // $(document).ready(function() {
    $(function() {
      $('.fromDate').datepicker({
        dateFormat: 'dd-mm-yy',
        changeMonth: true,
        changeYear: true,
        showAnim: 'slideDown',
        duration: 'fast',
        yearRange: new Date().getFullYear() + ':' + new Date().getFullYear(),
      });
    });
  &lt;/script&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form action="{{route('reports.leaveReport')}}" method="POST" class="form-horizontal" enctype="multipart/form-data"&gt;
    @csrf
    &lt;div class="container"&gt;
      &lt;div class="row"&gt;
        &lt;label for="from" class="col-form-label"&gt;From:&lt;/label&gt;
        &lt;div class="col-md-3"&gt;
          &lt;div class="input-group"&gt;
            &lt;div class="input-group-prepend"&gt;
              &lt;span class="input-group-text"&gt;&lt;i class="far fa-calendar-alt"&gt;&lt;/i&gt;&lt;/span&gt;
            &lt;/div&gt;
            &lt;input type="text" placeholder="dd/mm/yyyy" readonly autocomplete="off" name="from" value="{{$from}}" class="form-control fromDate"&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;label for="from" class="col-form-label"&gt;To:&lt;/label&gt;
        &lt;div class="col-md-3"&gt;
          &lt;div class="input-group"&gt;
            &lt;div class="input-group-prepend"&gt;
              &lt;span class="input-group-text"&gt;&lt;i class="far fa-calendar-alt"&gt;&lt;/i&gt;&lt;/span&gt;
            &lt;/div&gt;
            &lt;input type="text" placeholder="dd/mm/yyyy" readonly autocomplete="off" name="to" value="{{$to}}" class="form-control fromDate"&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="col-md-4"&gt;
          &lt;button type="submit" class="btn btn-primary btn-sm" name="search"&gt;Search&lt;/button&gt;
          &lt;button type="submit" class="btn btn-info btn-sm" name="exportPDF"&gt; &lt;i class="fa fa-file-pdf"&gt;&lt;/i&gt; Download as PDF&lt;/button&gt;
          &lt;button type="submit" class="btn btn-success btn-sm" name="exportExcel"&gt; &lt;i class="fa fa-file-excel"&gt;&lt;/i&gt;Download as Excel&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Route:</p>
  <pre><code>Route::get('reports/leaveReport', 'LeaveReportsController@leaveReport')-&gt;name('reports.leaveReport');
  Route::post('reports/leaveReport', 'LeaveReportsController@leaveReport')-&gt;name('reports.leaveReport');
  </code></pre>
  <p>I am using <code>JQuery UI datepicker</code> and <code>commencement_date</code> for <code>$from</code> and <code>$to</code>.</p>
  <p>When I submitted the form with the search button, the values in the JQueru-UI datepickers ($from and $to) are cleared.</p>
  <ol>
  <li><p>How do I retain these values</p>
  </li>
  <li><p>When the date fields are empty and the user submits, it throws error.</p>
  <p>#0 C:\xampp\htdocs\myapp\vendor<br />
  esbot\carbon\src\Carbon\Traits\Creator.php(645): Carbon\Carbon::rawCreateFromFormat('d-m-Y', NULL, NULL)</p>
  <p>#1 C:\xampp\htdocs\myapp\app\Http\Controllers\Report\LeaveReportsController.php(135): Carbon\Carbon::createFromFormat('d-m-Y', NULL)</p>
  </li>
  </ol>
  <p>How do I resolve these?</p>
  <p>Thanks</p>