laravel 从空值创建默认对象
laravel Creating default object from empty value
我有这个功能
function notifyStore($storeId, $notification,$type, $link)
{
$notify = new App\Store_notification;
$notify->store_id = $storeId;
$notify->notification = $notification;
$notity->link = $link;
$notify->type = $type;
$notify->save();
}
并在控制器中
$order = new Store_order;
$orderArray['user_id'] = $signed['user_id'];
$orderArray['store_id'] = $store->store_id;
$orderArray['payment_method'] = $signed['payment_id'];
$orderArray['address_info'] = $signed['address'];
$orderArray['invoice_id'] = $signed['invoice_id'];
$orderArray['order_status'] = 2;
$orderArray['created_at'] = Carbon::now()->format('Y-m-d H:i:s');
$invoice = $order->insertGetId($orderArray);
notifyStore($store->store_id,"You have a order to review",3,$signed['invoice_id']);
但是每次我提交订单时都会产生这个错误。我不知道它有什么问题。它说第 74 行有错误,第 74 行是 $notity->link = $link;
。任何人都可以检查并告诉我哪里出了问题吗?
错误
at HandleExceptions->handleError(2, 'Creating default object from empty value', 'C:\wamp64\www\ABCProject\app\Http\Helper.php', 74, array('storeId' => 1, 'notification' => 'You have a order to review', 'type' => 3, 'link' => '2017-1-6-888-8280', 'notify' => object(Store_notification), 'notity' => object(stdClass))) in Helper.php line 74
这是因为你的实体命名错误。仔细看你的第74行
$notity->link = $link;
你写的是 notity
而你的变量名是 notify
我有这个功能
function notifyStore($storeId, $notification,$type, $link)
{
$notify = new App\Store_notification;
$notify->store_id = $storeId;
$notify->notification = $notification;
$notity->link = $link;
$notify->type = $type;
$notify->save();
}
并在控制器中
$order = new Store_order;
$orderArray['user_id'] = $signed['user_id'];
$orderArray['store_id'] = $store->store_id;
$orderArray['payment_method'] = $signed['payment_id'];
$orderArray['address_info'] = $signed['address'];
$orderArray['invoice_id'] = $signed['invoice_id'];
$orderArray['order_status'] = 2;
$orderArray['created_at'] = Carbon::now()->format('Y-m-d H:i:s');
$invoice = $order->insertGetId($orderArray);
notifyStore($store->store_id,"You have a order to review",3,$signed['invoice_id']);
但是每次我提交订单时都会产生这个错误。我不知道它有什么问题。它说第 74 行有错误,第 74 行是 $notity->link = $link;
。任何人都可以检查并告诉我哪里出了问题吗?
错误
at HandleExceptions->handleError(2, 'Creating default object from empty value', 'C:\wamp64\www\ABCProject\app\Http\Helper.php', 74, array('storeId' => 1, 'notification' => 'You have a order to review', 'type' => 3, 'link' => '2017-1-6-888-8280', 'notify' => object(Store_notification), 'notity' => object(stdClass))) in Helper.php line 74
这是因为你的实体命名错误。仔细看你的第74行
$notity->link = $link;
你写的是 notity
而你的变量名是 notify