title: How to Retrieve and Store JSON data into Database using Laravel
body: <p>I am using Laravel-5.8 in my application, and I have this JSON record I have in Controller:</p>
  <pre><code>public function findLeaveCount(Request $request)
  {
      $nationalholidays = HrHolidayDate::select('holiday_date')
          -&gt;whereYear('created_at', '=', date('Y'))
          -&gt;get()
          -&gt;map(function ($nationalholiday) {
              return DateTime::createFromFormat('Y-m-d h:i:s', $nationalholiday-&gt;holiday_date)
                  -&gt;format('Y-m-d');
          });       
      return response()-&gt;json([
          'nationalholidays' =&gt; $nationalholidays,
      ]);           
  }
  </code></pre>
  <p>I retrieved it this way:</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;
    var holidayDays = [];
  $(document).ready(function() {
    $(document).on('change', '#leave_type', function() {
      $.ajax({
        type: 'get',
        url: '{{ route('
        get.employeeleavecounts.all ') }}',
        data: {
          'id': air_id
        },
        dataType: 'json', //return data will be json
        success: function(data) {
          $('#nationalholidays').val(data.nationalholidays);
          holidayDays = data.nationalholidays;
          console.log(holidayDays);
        },
        error: function() {
  
        }
      });
    });
  }); &lt;
  /script&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="hidden" id="nationalholidays" class="form-control"&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Which Gives me this in the console:</p>
  <pre><code>(7) [&quot;2020-11-12&quot;, &quot;2020-11-16&quot;, &quot;2020-11-19&quot;, &quot;2020-11-30&quot;, &quot;2020-12-14&quot;, &quot;2020-12-01&quot;, &quot;2020-12-10&quot;]
  0: &quot;2020-11-12&quot;
  1: &quot;2020-11-16&quot;
  2: &quot;2020-11-19&quot;
  3: &quot;2020-11-30&quot;
  4: &quot;2020-12-14&quot;
  5: &quot;2020-12-01&quot;
  6: &quot;2020-12-10&quot;
  length: 7
  __proto__: Array(0)
  </code></pre>
  <p>Then:</p>
  <pre><code> &lt;input type=&quot;hidden&quot; id=&quot;nationalholidays&quot; class=&quot;form-control&quot;&gt;
  </code></pre>
  <p>is presented this way:</p>
  <pre><code>2020-11-12,2020-11-16,2020-11-19,2020-11-30,2020-12-14,2020-12-01,2020-12-10
  </code></pre>
  <p>How do I make :</p>
  <pre><code>&lt;input type=&quot;hidden&quot; id=&quot;nationalholidays&quot; class=&quot;form-control&quot;&gt;
  </code></pre>
  <p>Present the data this way:</p>
  <pre><code> [&quot;2020-11-12&quot;, &quot;2020-11-16&quot;, &quot;2020-11-19&quot;, &quot;2020-11-30&quot;, &quot;2020-12-14&quot;, &quot;2020-12-01&quot;, &quot;2020-12-10&quot;]
  </code></pre>
  <p>because that's the format I want to store it into the database.</p>
  <p>Thanks</p>