本文整理汇总了PHP中app\Product::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::whereIn方法的具体用法?PHP Product::whereIn怎么用?PHP Product::whereIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Product
的用法示例。
在下文中一共展示了Product::whereIn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCart
public function getCart()
{
$cart_products = Product::whereIn('id', Session::get("pro_ids"))->get();
$session_price = Session::get("price");
$plan_duration = Session::get("duration");
return view('cart', compact('cart_products', 'session_price', 'plan_duration'));
}
示例2: treeProducts
public function treeProducts()
{
// Get ids of descendants
$categories = $this->leaves()->lists('id');
// Include the id of category itself
// $categories[] = $categories->getKey();
// Get Products
return Product::whereIn('category_id', $categories)->get();
}
示例3: getProductsStatus
public function getProductsStatus($date)
{
$res = new \StdClass();
$res->lists = [];
$listIds = [];
foreach (DB::table('daylist')->join('lists', 'daylist.list', '=', 'lists.id')->where('day', '=', $date)->get() as $l) {
$list = new \StdClass();
$list->id = $l->id;
$listIds[] = $l->id;
$list->done_products = round(DB::table('products')->select(DB::raw('sum(unitprice*quantity) as product_sum'))->whereNull('deleted_at')->where('list', '=', $l->id)->where('status', 'done')->first()->product_sum);
$list->all_products = round(DB::table('products')->select(DB::raw('sum(unitprice*quantity) as product_sum'))->whereNull('deleted_at')->where('list', '=', $l->id)->first()->product_sum);
$list->budget = round($l->budget);
$res->lists[] = $list;
}
$products = Product::whereIn('list', $listIds)->orderBy('status')->orderBy('name')->get();
$res->statuses = [];
$res->product_info = [];
foreach ($products as $product) {
$res->statuses[$product->status][] = $product->id;
$p = new \StdClass();
$p->id = $product->id;
$p->name = $product->name;
$p->unitprice = $product->unitprice;
$p->quantity = $product->quantity;
$p->moms = $product->moms;
$res->product_info[] = $p;
}
$res->deleted_products = [];
foreach (DB::table('products')->whereIn('list', $listIds)->whereNotNull('deleted_at')->get() as $p) {
$res->deleted_products[] = $p->id;
}
return response()->json($res);
}
示例4: index
public function index()
{
$employees = Employee::select('line_id')->where('manager_id', \Auth::user()->id)->get();
$products = Product::whereIn('line_id', $employees)->get();
$employees = Employee::select('id')->where('manager_id', \Auth::user()->id)->get();
$customers = Customer::whereIn('mr_id', $employees)->get();
$employees = Employee::where('manager_id', \Auth::user()->id)->get();
$dataView = ['productsCount' => count($products), 'plansCount' => AMPlan::where('month', \Config::get('app.current_month'))->count(), 'reportsCount' => AMReport::where('month', \Config::get('app.current_month'))->count(), 'customersCount' => count($customers), 'employeesCount' => count($employees)];
return view('am.index', $dataView);
}
示例5: index
public function index(Request $request)
{
$q = $request->get('q');
if ($request->has('cat')) {
$selected_category = Category::find($request->get('cat'));
// can't use this to get selected category > child's > product
// $products = $selected_category->products()->where('name', 'LIKE', '%'.$q.'%')->paginate(4);
// we use this to get product from current category and its child
$products = Product::whereIn('id', $selected_category->related_products_id)->where('name', 'LIKE', '%' . $q . '%')->paginate(4);
} else {
$products = Product::where('name', 'LIKE', '%' . $q . '%')->paginate(4);
}
return view('catalogs.index', compact('products', 'q', 'cat', 'selected_category'));
}
示例6: category
public function category($catename)
{
//$categories = Category::with('children')->where('parent_id', '=', 0)->orderBy('did')->get();
$main_category = Category::with('parent', 'children', 'children.products')->where('category_name', $catename)->firstOrFail();
if (count($main_category->parent) > 0) {
$parent_category = Category::with('children')->findOrFail($main_category->parent->id);
} else {
$parent_category = null;
}
//dd($parent_category);
$cate_products = Product::where('category_id', $main_category->id)->with(['images', 'prices', 'prices.unit', 'mrps'])->has('images')->has('prices')->orderBy('updated_at', 'desc')->get();
$sub_categories = Category::with('children')->where('parent_id', $main_category->id)->lists('id');
$sub_products = Product::whereIn('category_id', $sub_categories)->with('images', 'prices', 'prices.unit', 'mrps', 'mrps.unit')->has('images')->has('prices')->orderBy('updated_at', 'desc')->get();
//dd($cate_products);
$page_title = $main_category->category_name . ' - Best ' . $main_category->category_name . ' in Trichy';
//dd($page_title);
return view('site/category', compact('categories', 'main_category', 'cate_products', 'parent_category', 'sub_products', 'page_title'));
}
示例7: saveScore
public function saveScore(Request $request)
{
$stores_ids = $this->user->stores->pluck('id');
$this->_brands = Brand::join('store_brand as s', 's.bid', '=', 'brands.id')->whereIn('s.sid', $stores_ids)->get(['brands.*']);
$fids = Product::whereIn('bid', $this->_brands->pluck('id'))->pluck('fid');
$key = 'bonus_' . $this->user->getKey() . '_game';
$times = intval(Cache::get($key, 0));
$save_code_key = 'save_put_code_' . $this->user->getKey();
$ver_code = $request->get('ver_code');
if (session($save_code_key) == $ver_code && !empty($fids) && $times > 0) {
$fids = array_unique((array) $fids);
//把关注店铺,相关的厂商都加红包
$score = $request->get('score');
//分数
if ($score < 1) {
$data = ['err_msg' => '红包金额不能为空.'];
return $this->failure(NULL, false, $data, true);
}
$type_id = $request->get('type_id');
//活动id
foreach ($fids as $fid) {
$activity_bouns = new ActivityBonus();
$activity_bouns->uid = $this->user->getKey();
$activity_bouns->fid = $fid;
$activity_bouns->activity_id = with(Activity::where('fid', $fid)->where('type_id', $type_id)->first())->id;
$activity_bouns->bonus = intval($score) > 98 ? 98 : intval($score);
$activity_bouns->status = 0;
$activity_bouns->save();
}
Cache::decrement($key);
session([$save_code_key => '']);
//红包的个数
$bonus_cnt = ActivityBonus::where('uid', $this->user->getKey())->where('status', 0)->count();
$data = ['times' => --$times, 'bonus_cnt' => $bonus_cnt];
return $this->success(NULL, false, $data);
} else {
$data = ['err_msg' => '暂时没添加相关活动。'];
return $this->failure(NULL, false, $data, true);
}
}
示例8: recommend
public function recommend($curr_page, $pIdArray = array())
{
if (count($pIdArray)) {
$products = Product::whereIn('id', $pIdArray)->get();
} else {
$products = Product::all();
}
$user = Auth::user();
foreach ($products as $key => $eachproduct) {
$eachproduct->img = $eachproduct->imgloc('primary_packaging');
foreach ($eachproduct->preferences as $eachpreference) {
if ($eachpreference->user_id == $user->id && $eachpreference->flag == 0) {
$pid = $eachproduct->id;
unset($products[$key]);
continue;
}
}
}
foreach ($products as $key => $eachproduct) {
$score = $user->product_distance($eachproduct);
$eachproduct->score = $score;
unset($products[$key]['preferences']);
}
$sortedProducts = $products->toArray();
usort($sortedProducts, function ($a, $b) {
return $b['score'] - $a['score'];
});
$next_count = ($curr_page - 1) * 9;
$paginate['total_pages'] = floor(count($sortedProducts) / 9) + 1;
$paginate['prev_page'] = $curr_page - 1;
$paginate['next_page'] = $curr_page + 1;
if ($paginate['next_page'] > $paginate['total_pages']) {
$paginate['next_page'] = 0;
}
$sortedProducts = array_splice($sortedProducts, $next_count, 9);
return [$sortedProducts, $paginate];
}
示例9: getList
/**
* Shows list page.
*
* @param $id, the id of the list
* @return Response, a view for showing a specific list page.
*/
public function getList($date)
{
$res = DB::table('daylist')->where('day', '=', $date)->get();
$lists = $listIDs = [];
foreach ($res as $r) {
$list = ShoppingList::find($r->list);
$listIDs[] = $r->list;
$lists[] = $list;
$list->products()->orderBy('status')->orderBy('name')->get();
}
$products = Product::whereIn('list', $listIDs)->orderBy('status')->orderBy('name')->get();
return view('shop.list')->with('date', $date)->with('lists', $lists)->with('products', $products);
}
示例10: getTotalProductsAttribute
/**
* Get total amount of product from current category and its child
* @return int
*/
public function getTotalProductsAttribute()
{
return Product::whereIn('id', $this->related_products_id)->count();
}
示例11: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$arrProduct = $request->session()->get('Product');
$arrProductComplete = Product::whereIn('id', $arrProduct)->get();
return view('orders.index', ['products' => $arrProductComplete]);
}
示例12: news_feed_load_more
public function news_feed_load_more(Request $request)
{
$limit = 40;
$page = $request->page;
$class_name = $request->class_name;
$category_id = $request->category_id;
if ($class_name != null) {
$class = DB::select("select * from classes where replace(name,' ','') like ?", [$class_name])[0];
$usersIdOfThisClass = StudyClass::find($class->id)->registers()->select(DB::raw('user_id'))->get()->pluck('user_id');
$products = Product::whereIn('author_id', $usersIdOfThisClass)->orderBy('created_at', 'desc')->skip($page * $limit)->take($limit)->get();
} else {
if ($category_id != null) {
$category = CategoryProduct::find($category_id);
$products = $category->products()->orderBy('created_at', 'desc')->skip($page * $limit)->take($limit)->get();
} else {
$type = $request->type;
if ($type == 3) {
$products = Product::orderBy('created_at', 'desc')->where('type', '=', 2)->skip($page * $limit)->take($limit)->get();
} else {
if ($type == 2) {
$products = Product::orderBy('rating', 'desc')->skip($page * $limit)->take($limit)->get();
} else {
// $class = DB::select("select * from classes where replace(name,' ','') like ?", [$class_name])[0];
// $usersIdOfThisClass = StudyClass::find($class->id)->registers()->select(DB::raw('user_id'))->get()->pluck('user_id');
// $products = Product::whereIn('author_id', $usersIdOfThisClass)->orderBy('created_at', 'desc')->take($limit)->get();
$products = Product::orderBy('created_at', 'desc')->skip($page * $limit)->take($limit)->get();
}
}
}
}
$data['user'] = $this->user;
$data['products'] = $products;
return view('ajax.newsfeed_load_more', $data);
}
示例13: getItemsChildeAndSelf
/**
* @return mixed
*/
public function getItemsChildeAndSelf()
{
return Product::whereIn('catalog_id', $this->getChildeAndSelf())->active()->sort()->paginate(15);
}
示例14: getProductByCatIds
public static function getProductByCatIds($catId)
{
$catIds = static::getChildCatIds($catId);
$catIds = array_merge($catIds, (array) (int) $catId);
$categories = static::whereIn('id', $catIds)->get();
$arrProduct = [];
foreach ($categories as $category) {
foreach ($category->products as $product) {
$arrProduct[] = $product->id;
}
}
return $products = Product::whereIn('id', $arrProduct)->paginate(PAGINATE_NUM);
}
示例15: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id, $seo)
{
App\Product::where('id', $id)->increment('views');
$post = App\Blog::where('id', $id)->get()->first();
return \View::make('post', ['title' => 'Blog', 'favorites' => App\Product::orderBy('views', 'desc')->limit(6)->get(), 'post' => $post, 'relevant' => App\Product::whereIn('section_id', explode(';', $post->sections))->orderBy('views', 'desc')->limit(6)->get()]);
}