Laravel升级问题与何处有
我最近更改了Laravel的版本,现在出现以下错误:Laravel升级问题与何处有,laravel,eloquent,Laravel,Eloquent,我最近更改了Laravel的版本,现在出现以下错误: LogicException Has method invalid on "belongsTo" relations. 有人能解释为什么我现在会犯这个错误吗 如果我注释掉下面三行,没有错误 版本:“laravel/framework”:“4.1.7” 有问题的代码如下: $orderCount->whereHas('order', function($query) { $query->wh
LogicException
Has method invalid on "belongsTo" relations.
有人能解释为什么我现在会犯这个错误吗
如果我注释掉下面三行,没有错误
版本:“laravel/framework”:“4.1.7”
有问题的代码如下:
$orderCount->whereHas('order', function($query) {
$query->whereRaw("status IN ('pending', 'prepaid')");
});
此处的整个控制器逻辑:
public function show($id) {
// the fields we want back
$fields = array('id', 'title', 'description', 'msrp', 'brand_id', 'category_id');
// how many products are in pending orders
$orders = 0;
// assume not admin must be display = 1
$display = 1;
// if logged in add more fields
if(Auth::check()) {
// add these fields to the query if dealer
array_push($fields, 'price_dealer', 'quantity');
// if admin add these fields
if (Session::get("admin")) {
$display = 0;
array_push($fields, 'cost', 'display', 'crate_quantity_threshold', 'price_crate');
}
}
$product = Product::with('images', 'brand', 'category', 'docs')
->select($fields)
->where('display', '>=', $display)
->find($id);
if(Auth::check()) {
// make orders obj
// we need to see how many orders
// there are pending for this product
$obj = new OrderItem;
$orderCount = $obj->newQuery();
$orderCount->where('product_id', '=', $id);
$orderCount->whereHas('order', function($query) {
$query->whereRaw("status IN ('pending', 'prepaid')");
});
$product->orders = $orderCount->sum('quantity') > 0 ? $orderCount->sum('quantity') : 0;
// dd(\DB::getQueryLog());
}
if ($product) {
return Response::json(array(
'product' => json_decode($product)
),
200
);
} else {
return Response::json(array(
'flash' => "Not found"
),
500
);
}
}
订购型号:
public function products()
{
return $this->belongsToMany('Product', 'order_items', 'order_id', 'product_id');
}
简短回答:升级到4.1.11+,原因是: -未实现的方法
-方法到位这就是那天晚上晚些时候所做的。事实上,这是4.1.12。我还在composer.json中指定版本,以避免将来出现这种情况。谢谢