Laravel在哪里有升级问题

爵士乐

我最近更改了Laravel的版本,现在出现此错误:

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');
}
贾里克·特卡奇克(Jarek Tkaczyk)

简短答案:由于以下原因,升级到4.1.11+:

4.1.7-未实现的方法

4.1.11-适当的方法

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章