title: Inserting a JSON array from Laravel
body: <p>I'm wondering how I can loop insert an array value to database through Laravel.
  A sample of a Json is here:</p>
  
  <pre><code>[{"rid":"252","recipient_id":"1","email_type":"Body","to_cc_bcc":"to","start_dte":"2016-05-18","end_dte":""},{"rid":"252","recipient_id":"5","email_type":"Body","to_cc_bcc":"to","start_dte":"2016-05-18","end_dte":""}]
  </code></pre>
  
  <p>And my controller for storing such is this:</p>
  
  <pre><code>public function store()
      {
          // validate
          // read more on validation at http://laravel.com/docs/validation
          $rules = array(
              'name'       =&gt; 'required',
          );
          $validator = Validator::make(Input::all(), $rules);
  
          // process the login
          if ($validator-&gt;fails()) {
              return Redirect::to('reports')
                  -&gt;withErrors($validator)
                  -&gt;withInput(Input::except('password'));
          } else {
              //Dump Recipient array
              $cleanRecipients = json_decode(Input::get('test'), true);
                 foreach($cleanRecipients AS $value)
                      {
                              $report_recipient = new ReportRecipients;
                              $report_recipient-&gt;recipient_id       = $value['recipient_id'];
                              $report_recipient-&gt;rid       = $value['rid'];
                              $report_recipient-&gt;email_type = $value['email_type']; 
                              $report_recipient-&gt;to_cc_bcc = $value['to_cc_bcc'];
                              $report_recipient-&gt;start_dte = !empty($value['start_dte']) ? $value['start_dte'] : null;
                              $report_recipient-&gt;end_dte = !empty($value['end_dte']) ? $value['end_dte'] : null;
  
                      }
                          $report_recipient-&gt;save();
  
              // redirect
              Session::flash('message', 'Report was Successfully Saved!');
              return Redirect::to('reports');
  </code></pre>
  
  <p>What happens is that, it only stores the last set of values into the table and not all of them. I appreciate any help and thanks in advance.</p>