本文整理汇总了PHP中app\models\Category::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::where方法的具体用法?PHP Category::where怎么用?PHP Category::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
/**
* Show Category.
*
* @return Response
*/
public function show(Request $request, $slug)
{
$category = Category::where('slug', $slug)->first();
if (!$category) {
\App::abort(404);
}
// 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->getorder_by) {
$request->session()->put($session_type . '.order_by', $request->order_by);
}
if ($request->getorder_dir) {
$request->session()->put($session_type . '.order_dir', $request->order_dir);
}
$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');
$limit = $request->session()->get('limit');
$products = Product::whereIn('_id', $category->products)->orderBy($orderby, $request->session()->get($session_type . '.order_dir'))->paginate($limit);
return view('themes/basic/categories/show', ['category' => $category, 'products' => $products]);
}
示例2: show
/**
* Display the specified category.
*
* @param int $id
* @return Response
*/
public function show($alias, Advertisement $advertisement)
{
$category = Category::where('alias', $alias)->first();
$ads = $advertisement->approved()->where('category_id', $category->id)->orderBy('id', 'desc')->paginate(3);
return view('welcome', ['ads' => $ads]);
//->nest('child','task.index');
}
示例3: update
public function update(StoreCategoryRequest $request, $categoryId)
{
$input = $request->all();
$input['slug'] = str_replace(' ', '_', strtolower($input['name']));
$category = Category::where('id', $categoryId)->update($input);
return $this->createResponse($category);
}
示例4: feed
/**
* Список новостей
* @param Request $request
* @param null $alias
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function feed(Request $request, $alias = null)
{
$page = Paginator::resolveCurrentPage('page');
$per_page = config('paginator.per_page');
$category = Category::where('alias', $alias)->first();
$order_by = $request->input('order_by');
$articles = Article::whereRaw('1=1');
switch ($order_by) {
case 'name_desc':
$articles->orderBy('name', 'desc');
break;
case 'name_asc':
$articles->orderBy('name', 'asc');
break;
case 'date_desc':
$articles->orderBy('created_at', 'desc');
break;
case 'date_asc':
$articles->orderBy('created_at', 'asc');
break;
default:
$articles->orderBy('created_at', 'desc');
break;
}
if (is_null($category)) {
$articles = $articles->paginate($per_page);
} else {
$articles = $articles->where('category_id', $category->id)->paginate($per_page);
}
if ($order_by) {
$articles->appends('order_by', $order_by);
}
return view('pages/feed', ['articles' => $articles, 'category' => $category, 'page' => $page, 'order_by' => $order_by]);
}
示例5: __construct
public function __construct(Route $route)
{
$this->middleware(function ($request, $next) {
// if session is not set get it from .env SHOP_CODE
if (!$request->session()->has('shop')) {
$shop = Shop::where('code', config('app.shop_code'))->first();
$request->session()->put('shop', $shop->id);
}
// if limit is not set default pagination limit
if (!$request->session()->has('limit')) {
$request->session()->put('limit', 100);
}
// if session is not set reset the session for the language
if (!$request->session()->has('language')) {
$request->session()->put('language', config('app.locale'));
}
// if session is not set reset the session for the basket
if (!$request->session()->has('basket')) {
$request->session()->put('basket', ['subtotal' => 0, 'count' => 0, 'items' => []]);
}
// global list of categories
$categories = Category::where('shop_id', $request->session()->get('shop'))->orderBy('order', 'asc')->get();
// share globals
view()->share('language', $request->session()->get('language'));
view()->share('categories', $categories);
return $next($request);
});
// add controller & action to the body class
$currentAction = $route->getActionName();
list($controller, $method) = explode('@', $currentAction);
$controller = preg_replace('/.*\\\\/', '', $controller);
$action = preg_replace('/.*\\\\/', '', $method);
view()->share('body_class', $controller . '-' . $action);
}
示例6: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$groupOption = "food";
$menuOption = "categories";
$categories = Category::where('restaurant_id', Auth::user()->id)->get();
return view('backend.pages.categories')->with(compact('categories', 'menuOption', 'groupOption'));
}
示例7: confirmUnpublished
public function confirmUnpublished(Product $product)
{
$authors_list = $product->is->authors->lists('lastname');
$category = Category::where('id', $product->organizations->first()->pivot->cat_id)->first(['name']);
$editor = $product->is->editor->e_name;
return view('admin.products.unpublished.confirm', compact('product', 'authors_list', 'category', 'editor'));
}
示例8: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$videos = glob(public_path() . '/b/*');
usort($videos, function ($a, $b) {
$a = (int) basename($a, '.webm');
$b = (int) basename($b, '.webm');
if ($a == $b) {
return 0;
}
return $a < $b ? -1 : 1;
});
$category = \App\Models\Category::where('shortname', '=', 'misc')->first();
$user = \App\Models\User::find(1);
foreach ($videos as $video) {
if (\App\Models\Video::whereFile(basename($video))->count() > 0) {
continue;
}
$v = new \App\Models\Video();
$v->user()->associate($user);
$v->category()->associate($category);
$v->hash = sha1_file($video);
$v->file = basename($video);
$v->save();
}
}
示例9: getShoes
public function getShoes()
{
$categories = Category::where("is_home", 1)->orderBy("sort_order", "asc")->get();
foreach ($categories as $cat) {
$cat->image = asset("public/admin/uploads/catalog/category/" . json_decode($cat->images, true)[0]);
}
return $categories;
}
示例10: postAction
public function postAction(Request $request)
{
if ($request->input('id')) {
foreach ($request->input('id') as $k => $v) {
$cate = Category::where("id", $v)->delete();
}
}
return redirect('admin/category/index');
}
示例11: GetEditList
/**
* Data for Select element
*/
public static function GetEditList($id)
{
$result = [];
$list = Category::where('id', '!=', $id)->get();
foreach ($list as $k => $v) {
$result[$v->id] = $v->name;
}
return $result;
}
示例12: category_select
public function category_select(Request $request)
{
$lang = $request->session()->get('language');
$categories = [];
$results = Category::where('shop_id', '=', $request->session()->get('shop'))->get();
foreach ($results as $category) {
$categories[$category->id] = isset($category->{$lang}['name']) ? $category->{$lang}['name'] : $category->default['name'];
}
return $categories;
}
示例13: edit
/**
* Returns page with form for editing existing category
*
* @param App\Models\Category $category Instance of Category model
* @return View
*/
public function edit(Category $category)
{
/**
* Select id-slug list of all categories except itself, needed
* for choosing parent category
*/
$categories = Category::where('id', '<>', $category->id)->lists('slug', 'id');
$categories[''] = 'No parent (root)';
return view('admin.categories.edit')->with(compact('category', 'categories'));
}
示例14: authorize
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
//if(!parent::authorize()) return false;
if ($this->category) {
if ($this->user()->isAdmin()) {
return true;
}
return Category::where('id', $this->category)->where('user_id', $this->user()->id)->exists();
}
return true;
}
示例15: 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]);
}