/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $paginate = false; if ($request->has('search')) { $search = $request->get('search'); $products = Product::where('name', 'like', "%{$search}%")->orWhere('nicename', 'like', "%{$search}%")->orderBy('is_visible', 'desc')->orderBy('name', 'asc')->get(); } elseif ($request->has('filter')) { switch ($request->get('filter')) { case 'invisible': $products = Product::where('is_visible', false)->orderBy('name', 'asc')->get(); break; default: $paginate = true; $products = Product::orderBy('is_visible', 'desc')->orderBy('name', 'asc')->paginate(15); break; } } else { $paginate = true; $products = Product::orderBy('is_visible', 'desc')->orderBy('name', 'asc')->paginate(15); } return view('omnomcom.products.index', ['products' => $products, 'paginate' => $paginate]); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $account = Account::findOrFail($id); return view('omnomcom.accounts.show', ['account' => $account, 'products' => Product::where('account_id', $account->id)->paginate(30)]); }
public function generateOrder() { $products = Product::where('is_visible_when_no_stock', true)->whereRaw('stock < preferred_stock')->orderBy('name', 'ASC')->get(); return view('omnomcom.products.generateorder', ['products' => $products]); }