laravel - Return result set based on result from joined table -
laravel - Return result set based on result from joined table -
i building webstore application on laravel 4 , i've run bit of difficulty when building query. want homecoming list of products, have active amount of stock.
each item of stock listed own set of data, selling (tickets) have unique code attached , want know codes have been sold , have not.
i want able calculate how many tickets have remained unsold , list ticket groups active if have tickets left sold.
i going static query via products model returns each product , query homecoming codes have, seems long winded , i'm sure laravel has way homecoming result sets based upon internal query. i'm not sure how this..
hopefully makes sense, want quick , efficient way of checking products stock levels querying active products , querying active ticket stock.
some code snippets
// check if code active public function scopeactive($query) { homecoming $query->where('active', '=', 1); } // relationship product public function product() { homecoming $this->belongsto('product', 'product_id', 'id'); }
i want able grab products active codes guess $product->codes->product checking each product has active code, using product object through them?
my description wasn't clear found out wanted grouping result set product_id
in end did
return productcode::where('active', '=', 1) ->groupby('product_id') ->get();
hopefully might help looking - it's not efficient way of doing works..
laravel laravel-4
Comments
Post a Comment