奇怪的错误未定义的索引“项目”

时间:2017-03-23 20:49:09

标签: php arrays laravel laravel-4

我收到了这个错误。很奇怪因为索引存在。

这是数组:

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"
}

使用$ data的print_r共享屏幕截图 enter image description here

当我尝试使用Laravel中的下一行在数据库中搜索该记录时,会引发错误。

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

当系统需要创建一种项目时,不同的步骤会创建Var $数据......

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();
    }
}

1 个答案:

答案 0 :(得分:0)

好吧,伙计们,我不得不改变流程的方式来创建不同的项目来修复它。更多行代码但正在运行。

非常感谢。