本文整理汇总了PHP中app\Photo::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Photo::whereIn方法的具体用法?PHP Photo::whereIn怎么用?PHP Photo::whereIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Photo
的用法示例。
在下文中一共展示了Photo::whereIn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ProductOfCate
public function ProductOfCate($slug)
{
$cate_id = Category::where('slug', '=', $slug)->first();
$categories = Category::all();
$productOfcate = Product::where('category_id', $cate_id->id)->orderBy('created_at', 'DESC')->get();
$featured_products = FeaturedProduct::orderBy('rank', 'ASC')->get();
foreach ($featured_products as $i) {
$id[] = $i->product_id;
}
$featured_photo = Photo::whereIn('product_id', $id)->get();
$lastest_product = Product::orderBy('created_at', 'DESC')->limit(8)->get();
return view('pages.category', compact('productOfcate', 'cate_id', 'categories', 'featured_products', 'featured_photo', 'lastest_product'));
}
示例2: store
/**
* Product store
*
* @param ShopProductStoreRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(ShopProductStoreRequest $request)
{
$product = Product::create($request->only('name', 'content', 'price', 'active'));
if ($request->has('photos')) {
$photos = Photo::whereIn('id', $request->get('photos'))->get();
$product->photos()->saveMany($photos);
}
if ($request->has('category_id')) {
$product->categories()->attach($request->get('category_id'));
}
//@Todo check field before save
$product->fields()->attach(array_keys($request->field));
foreach ($request->get('field') as $fieldId => $value) {
if (!empty($value)) {
$field = Field::findOrFail($fieldId);
FieldValue::create([$field->type => $value[$field->type], 'product_id' => $product->id, 'field_id' => $field->id]);
}
}
if ($request->has('fields')) {
$product->fields()->attach($request->get('fields'));
}
Session::flash('message', 'Товар добавлен');
return redirect()->route('manager.shop.product.edit', $product->id);
}
示例3: update
/**
* Update Category
*
* @param ShopCategoryUpdateRequest $request
* @param $category
* @return \Illuminate\Http\RedirectResponse
*/
public function update(ShopCategoryUpdateRequest $request, Category $category)
{
$category->update(['name' => $request->get('name'), 'content' => $request->get('content')]);
if ($request->has('parent_id')) {
$parent = Category::find($request->get('parent_id'));
$parent->children()->save($category);
} else {
$category->parent_id = null;
$category->save();
}
if ($request->has('fields')) {
$category->fields()->sync($request->get('fields'));
}
if ($request->has('photos')) {
$photos = Photo::whereIn('id', $request->get('photos'))->get();
$category->photos()->saveMany($photos);
}
Session::flash('message', 'Категория изменено');
return redirect()->route('manager.shop.category.index');
}