eloquent - Laravel upgrade issue with whereHas -
eloquent - Laravel upgrade issue with whereHas -
i changed versions of laravel , getting error:
logicexception has method invalid on "belongsto" relations.
can explain why getting error?
if comment out below 3 lines, no error.
version: "laravel/framework": "4.1.7"
the piece of code in question this:
$ordercount->wherehas('order', function($query) { $query->whereraw("status in ('pending', 'prepaid')"); });
the entire controller logic here:
public function show($id) { // fields want $fields = array('id', 'title', 'description', 'msrp', 'brand_id', 'category_id'); // how many products in pending orders $orders = 0; // assume not admin must display = 1 $display = 1; // if logged in add together more fields if(auth::check()) { // add together these fields query if dealer array_push($fields, 'price_dealer', 'quantity'); // if admin add together 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()) { // create orders obj // need see how many orders // there pending 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) { homecoming response::json(array( 'product' => json_decode($product) ), 200 ); } else { homecoming response::json(array( 'flash' => "not found" ), 500 ); } }
in order model:
public function products() { homecoming $this->belongstomany('product', 'order_items', 'order_id', 'product_id'); }
short answer: upgrade 4.1.11+ due to:
4.1.7 - not implemented method
4.1.11 - method in place
laravel eloquent
Comments
Post a Comment