Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing foreach in PHP
    primarykey
    data
    text
    <p>I am trying to save data that is returned in array form to my table. However, I need to access the string in both GET inputs to do so. How can I achieve that? I can do it with one GET but not both. </p> <pre><code> public function postDisableDates() { $input = Input::all(); foreach($input['date'] as $date) { $db_date = strtotime($date); $dateFormat = date('Y-m-d', strtotime("-1 month", $db_date)); DB::table('bk_disable_date') -&gt;delete(); DB::table('bk_disable_date') -&gt;insert(array( 'date' =&gt; $dateFormat, 'office' =&gt; $input['office'] )); } } </code></pre> <p><strong>var dump $input</strong></p> <pre><code>array(3) { ["_token"]=&gt; string(40) "Dr0pu8RUbTTe1t058Fb3sDjKQLLk1KMBnBrpV7m6" ["office"]=&gt; array(4) { [0]=&gt; string(3) "Office1" [1]=&gt; string(10) "Office2" [2]=&gt; string(10) "Office3" [3]=&gt; string(10) "Office4" } ["date"]=&gt; array(4) { [0]=&gt; string(17) "25 December, 2013" [1]=&gt; string(17) "14 December, 2013" [2]=&gt; string(17) "05 December, 2013" [3]=&gt; string(17) "23 November, 2013" } } </code></pre> <p><strong>var dump of $dateFormat in foreach loop</strong></p> <pre><code>string(10) "2013-11-25" string(10) "2013-11-14" string(10) "2013-11-05" string(10) "2013-10-23" </code></pre> <p>The $dateFormat part seems to be ok. I just need the office part to work the same way. Probably an easier way to achieve this.</p> <p>my input names are set up as office[] and date[]. If that helps. </p> <p><strong>The disable date table is as follows</strong></p> <pre><code>id date office 30 2013-11-25 Office1 31 2013-11-14 Office2 32 2013-11-05 Office3 33 2013-10-23 Office4 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload