本文整理汇总了PHP中app\Product::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::with方法的具体用法?PHP Product::with怎么用?PHP Product::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Product
的用法示例。
在下文中一共展示了Product::with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: details
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function details($id)
{
$details = Product::with('range', 'group')->find($id);
Session::flash('keywords', '');
Session::flash('title', '');
return View::make('details', compact('details'));
}
示例2: index
public function index(Request $request)
{
$products = Product::with('tags', 'category', 'picture')->online()->orderBy('published_at', 'desc')->paginate(5);
if ($request->ajax()) {
return response()->json(View::make('partials.listProduct', array('products' => $products))->render());
}
return view('front.index', compact('products'));
}
示例3: show
public function show($id)
{
$product = Product::with('images')->with('manufacturer')->find($id);
if (is_null($product)) {
$this->code = 404;
}
return Response::json($product, $this->code);
}
示例4: single
public function single($cate, $slug)
{
$products = Product::where('feature', true)->get()->take(4);
$products1 = Product::where('feature', false)->get()->take(6);
$product = Product::with(['image' => function ($q) {
$q->addSelect('product_id', 'image_name');
}])->where('slug', $slug)->get();
return view('frontend.pages.product', compact('product', 'products', 'products1'));
}
示例5: index
public function index(Request $request)
{
// Show a View to Load All Products in Tabular Form
$query = Product::with(["category"]);
$category = $request->input("categoryID");
if ($category) {
$query->where("category_id", $category);
}
return $query->get();
}
示例6: index
/**
* Display a listing of products under infinite scroll with pagination loading
*
* @param Request $request
*/
public function index(Request $request)
{
$products = Product::with('tags', 'category', 'picture')->online()->orderBy('published_at', 'desc')->paginate($this->paginate);
$lastPage = $products->lastPage();
$title = "Welcome Home Page";
if ($request->ajax()) {
return response()->json(['html' => view('front.blocProd', ['products' => $products, 'lastPage' => $lastPage, 'title' => $title])->render()]);
}
return view('front.index', compact('products', 'lastPage', 'title'));
}
示例7: __construct
public function __construct()
{
// $productQuery = Globex::with('images')->select('id', 'title', 'description', 'price', DB::raw('0 as type'));
// $adQuery = Advertisement::with('images')->select('id', 'title', 'description','price', DB::raw('1 as type'));
// $motorQuery = Motor::with('images')->select('id', 'title', 'description','price', DB::raw('2 as type'));
// $this->products = $adQuery->get()->merge($productQuery->get())->merge($motorQuery->get());
$this->products = Product::with('producible')->get();
$this->emirates = Emirate::all();
$this->cats = Category::whereDepth(0)->get();
}
示例8: product
public function product($id, $alias)
{
$product = Product::with('images')->findOrFail($id);
if ($product->alias != $alias) {
return view('errors.404');
}
$new_products = Product::orderBy('order')->where('id_category', $product->id_category)->take(4)->get();
// increasing product view everytime function called
DB::table('product')->where('id', $id)->increment('view', 1);
return view('detail', compact('product', 'new_products'));
}
示例9: edit
public function edit($id)
{
$product = Product::with('categories')->find($id);
$categories = Category::withDepth()->get();
$categories_id = array();
foreach ($product->categories as $category) {
$categories_id[] = $category->id;
}
$categories = $categories->toTree();
return view('products.edit', ['product' => $product, 'categories' => $categories, 'categories_id' => $categories_id]);
}
示例10: detail
public function detail(Request $request)
{
$pid = $request->input('pid');
$this->_product = Product::with(['brand', 'covers', 'attrs', 'sizes'])->find($pid);
if (empty($this->_product)) {
return $this->failure_noexists();
}
$this->subtitle($this->_product->brand->name);
$this->subtitle($this->_product->title);
return $this->view('m.detail');
}
示例11: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$product = Product::with('nutrients', 'detail')->find($id);
if (!is_object($product)) {
return response()->json(['error' => 'Product not found'], 404);
}
$data = ['id' => $product->id, 'description' => $product->description, 'food_group' => $product->food_group, 'sn' => $product->detail->scientific_name, 'cn' => $product->detail->commercial_name, 'manu' => $product->detail->manufacturer, 'nf' => $product->detail->nitrogen_to_protein_conversion_factor, 'cf' => $product->detail->carbohydrate_factor, 'ff' => $product->detail->fat_factor, 'pf' => $product->detail->protein_factor, 'r' => $product->detail->refuse_percent, 'rd' => $product->detail->refuse_description, 'nutrients' => $product->nutrients->map(function ($nutrient) {
return ['id' => $nutrient->id, 'title' => $nutrient->name, 'group' => $nutrient->group, 'unit' => $nutrient->unit, 'value' => $nutrient->pivot->value];
})];
// dd(response()->json($data));
return response()->json($data);
}
示例12: showDashboard
public function showDashboard()
{
$food = Product::with('category')->whereHas('category', function ($q) {
$q->food();
})->enabled()->get();
$drinks = Product::with('category')->whereHas('category', function ($q) {
$q->drinks();
})->enabled()->get();
$other = Product::with('category')->whereHas('category', function ($q) {
$q->other();
})->enabled()->get();
$this->updateCart();
$spendings = Auth::user()->unpaidOrders->sum('total_price');
return view('dashboard', ['food' => $food, 'drinks' => $drinks, 'other' => $other, 'items' => $this->items, 'price' => $this->price, 'spendings' => $spendings]);
}
示例13: compose
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
$categories = Category::with('children', 'products')->where('parent_id', '=', 0)->orderBy('did')->get();
$hotpros_id = Salesstats::groupBy('product_id')->take(16)->get();
$hotpros_id = $hotpros_id->lists('product_id');
$hotpros = Product::with('images')->has('images')->has('prices')->wherein('id', $hotpros_id)->take(16)->get();
$globals = DB::table('globalsettings')->get();
$dts = DB::table('deliverytimes')->where('active', true)->get();
foreach ($dts as $dt) {
$dt->start = Carbon::parse($dt->start)->format('h:ia');
$dt->stop = Carbon::parse($dt->stop)->format('h:ia');
}
$settings = [];
foreach ($globals as $global) {
$name = $global->name;
$value = $global->value;
$settings[$name] = $value;
}
$offers = Offer::with(['categories', 'categories.products' => function ($q) {
$q->has('images');
}, 'brands', 'brands.products' => function ($q) {
$q->has('images');
}, 'products' => function ($q) {
$q->has('images');
}, 'products.images', 'products.prices'])->where('active', true)->where('start', '<=', Carbon::today()->toDateString())->where('end', '>=', Carbon::today()->toDateString())->take(16)->get();
//dd($offers);
$feedbacks = Feedback::with('user')->take(8)->get();
if ($user = Sentinel::check()) {
$user = User::findorfail($user->id);
$flashes = Flashtext::where('active', '1')->get();
$areas = Area::where('deliverable', '1')->get();
$viewpros_id = Viewstats::where('user_id', $user->id)->take(16)->get();
//dd($viewpros_id);
$viewpros_id = $viewpros_id->lists('product_id');
$viewpros = Product::with('images')->has('images')->has('prices')->wherein('id', $viewpros_id)->take(16)->get();
$view->with(['user' => $user, 'flashes' => $flashes, 'areas' => $areas, 'hotpros' => $hotpros, 'viewpros' => $viewpros, 'offers' => $offers, 'settings' => $settings, 'dts' => $dts, 'feedbacks' => $feedbacks, 'categories' => $categories]);
} else {
$flashes = Flashtext::where('active', '1')->get();
$areas = Area::where('deliverable', '1')->get();
$viewpros_id = Viewstats::where('user_id', 0)->take(16)->get();
$viewpros_id = $viewpros_id->lists('product_id');
$viewpros = Product::with('images')->has('images')->has('prices')->wherein('id', $viewpros_id)->take(16)->get();
$view->with(['flashes' => $flashes, 'areas' => $areas, 'hotpros' => $hotpros, 'viewpros' => $viewpros, 'offers' => $offers, 'settings' => $settings, 'dts' => $dts, 'feedbacks' => $feedbacks, 'categories' => $categories]);
}
}
示例14: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
if (Auth::user()->is_admin) {
$products = Product::with('category')->get();
} else {
$productsAll = Product::with(['category' => function ($query) {
$query->active();
}])->sell()->get();
$products = [];
foreach ($productsAll as $product) {
if ($product->category !== null) {
$products[] = $product;
}
}
}
$view = 'index';
if (!Auth::user()->is_admin) {
$view .= '_client';
}
return view('products.' . $view, compact('products'));
}
示例15: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($slug, $id)
{
$list_color = Product::find($id)->color;
$list_size = Product::find($id)->size;
$size = Size::all();
$color = Color::all();
$products = Product::with(['category' => function ($querry) {
$querry->addSelect('id', 'cate_name');
}, 'brand' => function ($query) {
$query->addSelect(['id', 'brand_name']);
}, 'image' => function ($q) {
$q->addSelect('product_id', 'image_name');
}])->where('slug', $slug)->get();
foreach ($products as $product) {
return view('admin.product.edit', compact('product', 'list_color', 'list_size', 'size', 'color'));
}
}