本文整理汇总了PHP中app\models\Product::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::where方法的具体用法?PHP Product::where怎么用?PHP Product::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$pro = new Product();
$adSlotObj = new Adslot();
$catObj = new Category();
$brandObj = new Brand();
/*getting all products for all slots(currently we have 7 slots)*/
$adSlot_data = $adSlotObj->with(['products'])->get();
/*t1-t7*/
// dd($adSlot_data[4]['products'][0]);
$category_temp_data = $catObj->orderBy('created_at')->take(10)->get();
/*f1-f10*/
$brand_data = $brandObj->with(['products'])->get();
$category_data = [];
foreach ($category_temp_data as $cat_id) {
$cat_latest_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('photo_1');
$cat_latest_product_id = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('id');
$cat_random_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy(DB::raw('RAND()'))->take(6)->get();
$cat_brands = $pro->with(['brand'])->where('category_id', '=', $cat_id['id'])->take(5)->get();
$cat_products_random_photos = [];
foreach ($cat_random_product as $photo) {
$cat_products_random_photos[] = $photo;
}
$category_data[] = ['color' => $cat_id['color'], 'floor' => $cat_id['floor'], 'name' => $cat_id['name'], 'desc' => $cat_id['description'], 'logo' => $cat_id['logo'], 'latest_photo_id' => $cat_latest_product_id, 'latest_photo' => $cat_latest_product, 'random_photos' => $cat_products_random_photos, 'brands' => $cat_brands];
}
return view('landing_page', compact(['adSlot_data', 'category_data']));
}
示例2: index
/**
* List all products.
*
* @return Response
*/
public function index(Request $request)
{
// pagination
$session_type = 'product';
if (!$request->session()->has('order_by')) {
$request->session()->put($session_type . '.order_by', 'created_at');
}
if (!$request->session()->has('order_dir')) {
$request->session()->put($session_type . '.order_dir', 'desc');
}
if ($request->order_by) {
$request->session()->put($session_type . '.order_by', $request->order_by);
}
if ($request->order_dir) {
$request->session()->put($session_type . '.order_dir', $request->order_dir);
}
$limit = $request->session()->get('limit');
$orderby = $request->session()->get($session_type . '.order_by') == 'created_at' ? $request->session()->get($session_type . '.order_by') : $request->session()->get('language') . '.' . $request->session()->get($session_type . '.order_by');
// query products with conditional search
$products = Product::where('shop_id', $request->session()->get('shop'))->where(function ($query) use($request) {
if ($request->search) {
return $query->where('en.name', 'LIKE', '%' . $request->search . '%');
}
})->orderBy($orderby, $request->session()->get($session_type . '.order_dir'))->paginate($limit);
$products->search = $request->search;
return view('admin/products/index', ['products' => $products]);
}
示例3: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id, $itemId)
{
$product = Product::where('id', '=', $id)->where('user_id', '=', Auth::user()->id)->first();
$order->items()->delete($itemId);
$this->recalculateDelivery($order);
return $this->orderToJson($order);
}
示例4: show
/**
* Change the currency.
*
* @return Redirect
*/
public function show(Request $request, string $currency)
{
$request->session()->put('currency', $currency);
$currency = Currency::where('currency', $currency)->first()->toArray();
$request->session()->put('currency_rate', $currency['rate']);
// we need to update the basket
$basket = $request->session()->get('basket');
foreach ($basket['items'] as $id => $item) {
if (isset($item['parent_sku'])) {
// its an option
$product = Product::where('sku', $item['parent_sku'])->first();
$price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price;
foreach ($product->option_values as $option) {
if ($option['sku'] == $id) {
$price = number_format($option['price'] * $request->session()->get('currency_rate'), 2, '.', '');
}
}
} else {
$product = Product::find($id);
$price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price;
}
$basket['items'][$id]['price'] = $price;
}
$request->session()->put('basket', $basket);
return redirect()->back();
}
示例5: show
/**
* Show Product.
*
* @return Response
*/
public function show($slug)
{
$product = Product::where('slug', $slug)->first();
$file_size = key(array_reverse(config('image.image_sizes')));
//smallest
$product->files = $this->getFiles('images/products/' . $product->id . '/' . $file_size);
return view('themes/basic/products/show', ['product' => $product]);
}
示例6: getFilterCategory
public function getFilterCategory($id)
{
$categories = [0 => 'Все'];
foreach (Category::all() as $category) {
$categories[$category->id] = $category->name;
}
return view('admin.products.index', ['products' => Product::where('category_id', '=', $id)->paginate(15), 'categories' => Category::tree()]);
}
示例7: showProductsByCat
public function showProductsByCat($id)
{
if (is_null($id) || empty($id)) {
die('Некорректный идентификатор категории');
}
$products = Product::where('catid', $id)->get();
return view('products.default', ['products' => $products]);
}
示例8: add
/**
* Adds product to cart
*
* @param AddToCartRequest $request
*/
public function add(AddToCartRequest $request)
{
$product = Product::where('active', 1)->findOrFail((int) $request->product_id);
if ($product) {
Cart::associate('App\\Models\\Product')->add($product->id, $product->name, 1, $product->price);
}
return back();
}
示例9: ajaxSearch
public function ajaxSearch(Request $request, $keyword)
{
if ($request->ajax() && $request->isMethod('GET') && trim($keyword) !== '') {
$stores = Store::where('name', 'LIKE', "%{$keyword}%")->take(10)->get(['slug', 'name']);
$products = Product::where('name', 'LIKE', "%{$keyword}%")->take(10)->get(['id', 'name']);
$users = User::where('first_name', 'LIKE', "%{$keyword}%")->orWhere('last_name', 'LIKE', "%{$keyword}%")->orWhere('user_name', 'LIKE', "%{$keyword}%")->take(10)->get(['user_name', 'first_name', 'last_name']);
return pong(1, ['data' => ['stores' => $stores, 'products' => $products, 'users' => $users]]);
}
}
示例10: getSearch
public function getSearch()
{
$term = Input::get('search_query');
if ($term != '') {
$products = Product::where('availability', 1)->where('name', 'like', "%{$term}%")->orWhere('article', 'like', "%{$term}%")->get();
return view('products.index', ['products' => $products]);
} else {
return Redirect::route('home');
}
}
示例11: show
/**
* Show the application dashboard.
*
* @return Response
*/
public function show(Request $request)
{
$stats['categories'] = Category::where('shop_id', '=', $request->session()->get('shop'))->count();
$stats['products'] = Product::where('shop_id', '=', $request->session()->get('shop'))->count();
$stats['customers'] = User::where('shop_id', '=', $request->session()->get('shop'))->count();
$stats['pages'] = Page::where('shop_id', '=', $request->session()->get('shop'))->count();
$stats['blogs'] = Blog::where('shop_id', '=', $request->session()->get('shop'))->count();
$stats['orders'] = Order::where('shop_id', '=', $request->session()->get('shop'))->count();
$stats['revenue'] = Order::where('shop_id', '=', $request->session()->get('shop'))->sum('total');
return view('admin/dashboard', ['stats' => $stats]);
}
示例12: action_clear
public function action_clear()
{
$products = \App\Models\Product::where('catalog_id', '=', 2)->get();
$this->output->progressStart(count($products));
foreach ($products as $product) {
$this->info($product->id);
$product->images()->delete();
$product->delete();
$this->output->progressAdvance();
}
$this->output->progressFinish();
}
示例13: delete
public function delete()
{
$id = Input::get('id');
$getcount = Product::where("attr_set", "=", $id)->count();
if ($getcount <= 0) {
AttributeSet::find($id)->attributes()->detach();
AttributeSet::find($id)->delete();
return redirect()->back()->with('message', 'Attribute Set deleted successfully!');
} else {
return redirect()->back()->with('message', 'Sorry This Attribute Set is Part of a Product! Delete the Product First!');
}
}
示例14: deleteDistributor
/**
* @param $dist_id
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function deleteDistributor($dist_id)
{
$dist = Distributor::where('id', $dist_id);
$products = Product::where('distributor_id', '=', $dist_id);
if ($products->count()) {
return response()->json(['deleted' => false, 'products' => true]);
} else {
if ($dist->delete()) {
return response()->json(['deleted' => true, 'products' => false]);
}
return response()->json(['deleted' => false]);
}
}
示例15: destroy
public function destroy($id)
{
$supplier = Supplier::find($id);
if ($supplier) {
$deleteProduct = Product::where('supplier_id', '=', $id)->delete();
if ($supplier->delete()) {
return ['status' => 'success', 'message' => 'Supplier data successfully deleted.'];
} else {
return ['status' => 'failed', 'message' => 'Supplier data failed to deleted.'];
}
} else {
return ['status' => 'failed', 'message' => 'Supplier data not found.'];
}
}