本文整理汇总了PHP中app\models\Product::join方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::join方法的具体用法?PHP Product::join怎么用?PHP Product::join使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::join方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
$categories = Input::get('cat');
$per_page = 1000;
//!IMPORTANT
if ($categories != "") {
if (Input::get("page") != "") {
$page = (int) Input::get("page");
} else {
$page = 1;
}
if ($page == 1) {
$page_calc = 0;
} else {
$page_calc = $page;
}
$cat_array = explode(",", $categories);
$all_products = Product::join('product_cat', 'products.id', '=', 'product_cat.product_id')->whereIn('product_cat.cat_id', $cat_array)->get();
$all_products_count = count($all_products);
$last_page = ($all_products_count - $per_page) / $per_page + 1;
$products_pivot = Product::join('product_cat', 'products.id', '=', 'product_cat.product_id')->whereIn('product_cat.cat_id', $cat_array)->skip($page_calc * $per_page - 1)->take($per_page)->get();
$unique_products = [];
foreach ($products_pivot as $item) {
$found = false;
foreach ($unique_products as $compare_item) {
if ($item->product_id == $compare_item->product_id) {
$found = true;
break;
}
}
if (!$found) {
$unique_products[] = $item;
}
}
$products = [];
foreach ($unique_products as $product) {
$new_product = Product::find($product->product_id);
$new_product->product_photos = $new_product->product_photos()->where("is_preview", "=", 1)->get();
$products[] = $new_product;
}
$products = $this->buildPaginationResponse($products, $all_products_count, $per_page, $page, $last_page, $categories);
} else {
// $products = Product::paginate($per_page);
$products = Product::with("product_photos")->with(array('product_photos' => function ($query) {
$query->where('is_preview', '=', 1);
}));
$products = $products->paginate($per_page);
}
return $products;
}
示例2: getProductsByTag
/**
* @param $id
* @return mixed
*/
public function getProductsByTag($id)
{
$tag = new Tag();
$listChildId = $tag->getIdChildsById($id);
$listChildId[] = $id;
$query = Product::join('product_tag', 'product.id', '=', 'product_tag.product_id')->whereIn('product_tag.tag_id', $listChildId)->orderBy('created')->get();
return $query;
}