2

配列形式で返されたデータをテーブルに保存しようとしています。ただし、そのためには、両方の GET 入力で文字列にアクセスする必要があります。どうすればそれを達成できますか?1 つの GET で実行できますが、両方では実行できません。

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

    DB::table('bk_disable_date')
            ->insert(array(
                'date' => $dateFormat,
                'office' => $input['office']
            ));                     
    }       

}

var ダンプ $input

array(3) { ["_token"]=> string(40) "Dr0pu8RUbTTe1t058Fb3sDjKQLLk1KMBnBrpV7m6" ["office"]=> array(4) { [0]=> string(3) "Office1" [1]=> string(10) "Office2" [2]=> string(10) "Office3" [3]=> string(10) "Office4" } ["date"]=> array(4) { [0]=> string(17) "25 December, 2013" [1]=> string(17) "14 December, 2013" [2]=> string(17) "05 December, 2013" [3]=> string(17) "23 November, 2013" } } 

foreach ループでの $dateFormat の var ダンプ

string(10) "2013-11-25" string(10) "2013-11-14" string(10) "2013-11-05" string(10) "2013-10-23" 

$dateFormat 部分は問題ないようです。オフィスの部分も同じように機能する必要があります。おそらくこれを達成するためのより簡単な方法です。

私の入力名はoffice[]とdate[]として設定されています。それが役立つ場合。

無効化の日付表は次のとおりです。

id  date    office
30  2013-11-25  Office1
31  2013-11-14  Office2
32  2013-11-05  Office3
33  2013-10-23  Office4
4

1 に答える 1

3

オフィスと日付のキーが同じである場合 (私はそう思います)、それを試すことができます:

public function postDisableDates() {

  $input = Input::all();  

  DB::table('bk_disable_date')
    ->delete();

  foreach($input['date'] as $key => $date) {

    $db_date = strtotime($date);
    $dateFormat = date('Y-m-d', strtotime("-1 month", $db_date));

    DB::table('bk_disable_date')
      ->insert(array(
        'date' => $dateFormat,
        'office' => $input['office'][$key]
      )
    );                     
  }       
}

それが役立つことを願っています

于 2013-11-11T01:06:08.983 に答える