2017-03-23 11 views
1

このエラーが発生しました。インデックスが存在するために奇妙です。奇妙なエラー未定義のインデックス "アイテム"

これは配列です:

私はLaravelに次の行を使用してデータベースにそのレコードを検索しようとすると、エラーがスローされた$データ enter image description here

のますprint_rでスクリーンショットを共有

array(8) { 
["OrderID"]=> 
    string(6) "201646" 
["FolioNo"]=> 
    string(12) "540840840840" 
["InvoiceID"]=> 
    string(3) "277" 
["CreatedOn"]=> 
    object(Illuminate\Database\Query\Expression)#1252 (1) { 
    ["value":protected]=> 
     string(9) "GETDATE()" 
    } 
["CreatedBy"]=> 
    string(1) "4" 
["Item"]=> 
    string(8) "Lien New" 
["ItemDescriptions"]=> 
    string(8) "Lien New" 
["ItemPrice"]=> 
    string(6) "150.00" 
} 

$itemExist = InvoiceItem::where('OrderID', $data['OrderID'])->where('Item', $data['Item'])->pluck('ItemID'); 

システムは、アイテムの種類を作成する必要がある場合ヴァール$データは、異なる工程で作成された...

private function createRushInvoiceItem($order){ 
    if($order->IsRUSHOrder == 1){ 
     $data = $this->getExpensesData($order); 
     $data = array_merge($data, [ 
      'Item' => "Lien RUSH", 
      'ItemDescriptions' => "Lien RUSH", 
      'ItemPrice' => $this->getClientPrice($order, 3) 
     ]); 

     $this->createInvoiceItem($data); 
    } 
} 

最初、私は共通の値を設定しています:

public function getExpensesData($order) { 
    $data = [ 
     "OrderID" => $order->OrderID, 
     "FolioNo" => $order->Property->FolioNo, 
     'InvoiceID' => $this->getInvoiceID($order->OrderID), 
    ]; 

    # Getting timeStamps for this record on create 
    $data = $this->setTimeStamps($data, 'C'); 
    return $data; 
} 

public function setTimeStamps($data, $section) { 
    if($section == 'C') { 
     $data = array_merge($data, [ 
      'CreatedOn' => DB::raw('GETDATE()'), 
      'CreatedBy' => Auth::user()->UserID 
     ]); 
    } else { 
     $data = array_merge($data, [ 
      'UpdatedOn' => DB::raw('GETDATE()'), 
      'UpdatedBy' => Auth::user()->UserID 
     ]); 
    } 
    return $data; 
} 

最後にアイテムを作成していますが、ここにエラーが表示されます

public function createInvoiceItem($data) { 
    $itemExist = InvoiceItem::where('OrderID', $data['OrderID'])->where('Item', $data['Item'])->pluck('ItemID'); 

    try { 
     return !is_null($itemExist)? InvoiceItem::where('ItemID', $itemExist)->update($data) : InvoiceItem::create($data); 
    } 
    catch (Expection $exc) { 
     return $exc->getMessage(); 
    } 
} 
+0

そのままコードに問題はありません。 $ dataが定義されているコードを追加できますか? –

+0

確かな男!私はすでにやった! –

+0

あなたは正しいです、私は 'var_dump'で催眠術を受けました。 –

答えて

0

さて、みんな、私はそれを修正するために異なる項目を作成するプロセスの方法を変更しなければならなかった。より多くのコード行が動作しています。

ありがとうございます。

関連する問題