Blame view
app/Http/Controllers/MainController.php
4.58 KB
b80175387 Начальный проект ... |
1 2 3 |
<?php namespace App\Http\Controllers; |
1bd0c6ebe Админка, товары. ... |
4 5 |
use App\Models\Banner; use App\Models\Category; |
2f5f2c1a4 Баг с версткой ка... |
6 |
use App\Models\Good; |
c5f46e4d5 Таблица просматри... |
7 |
use App\Models\Good_Look; |
2f5f2c1a4 Баг с версткой ка... |
8 |
use App\Models\News; |
b80175387 Начальный проект ... |
9 |
use Illuminate\Http\Request; |
2f5f2c1a4 Баг с версткой ка... |
10 |
use Symfony\Component\HttpFoundation\Session\Storage; |
b80175387 Начальный проект ... |
11 12 13 |
class MainController extends Controller { |
2f5f2c1a4 Баг с версткой ка... |
14 |
// Главная страница |
e73374e87 Каталог ajax, адм... |
15 |
public function index(Request $request) { |
1bd0c6ebe Админка, товары. ... |
16 17 |
$banners = Banner::query()->orderBy('id')->get(); $category = Category::query()->where('parent_id', '>', '0')->orderBy('id')->get(); |
2f5f2c1a4 Баг с версткой ка... |
18 |
|
e73374e87 Каталог ajax, адм... |
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
if (isset($request->filter)) { switch($request->filter) { case 'news':$goods = Good::query()->where('new', '=', '1')->orderBy('id')->paginate(8); break; case 'stock':$goods = Good::query()->where('stock_count', '>', '0')->orderBy('id')->paginate(8); break; case 'demo':$goods = Good::query()->where('demo', '=', '1')->orderBy('id')->paginate(8); break; case 'way':$goods = Good::query()->where('way', '=', '1')->orderBy('id')->paginate(8); break; } } else { $goods = Good::query()->where('new', '=', '1')->orderBy('id')->paginate(8); } if ($request->ajax()) { return view('index_catalog', compact('goods')); } |
2f5f2c1a4 Баг с версткой ка... |
37 |
|
e73374e87 Каталог ajax, адм... |
38 |
$news = News::query()->where('status', '=', 'новость')->orderByDesc('id')->paginate(3); |
2f5f2c1a4 Баг с версткой ка... |
39 |
return view('index', |
e73374e87 Каталог ajax, адм... |
40 |
compact('banners', 'category', 'goods', 'news')); |
b80175387 Начальный проект ... |
41 42 43 44 45 |
} public function about_company() { return view('company'); } |
477c05de1 Каталог страница,... |
46 |
public function catalog(Request $request) { |
295e31db7 Флаги производите... |
47 |
$items = Category::all(); |
477c05de1 Каталог страница,... |
48 |
$goods = Good::query(); |
e73374e87 Каталог ajax, адм... |
49 |
$articles = News::query()->where('status', '=', 'статья')->paginate(10); |
c5f46e4d5 Таблица просматри... |
50 51 52 53 |
$reviews = News::query()->where('status', '=', 'отзыв')->paginate(10); $lookin = Good_Look::query()->orderByDesc('id')->limit(4)->pluck('goods_id') ->toArray(); $lookin_good = Good::query()->whereIn('id', $lookin)->get(); |
477c05de1 Каталог страница,... |
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
if (!empty($request->filter)) { $filter = json_decode($request->filter); if (is_array($filter)) if (count($filter) > 0) $goods = $goods->whereIn('manufacturer', $filter); } if ($request->sort == 'count') { $goods = $goods->orderByDesc('stock_count')->orderByDesc('id'); } if ($request->sort == 'price') { $goods = $goods->orderBy('price')->orderByDesc('id'); } $goods = $goods->paginate(6); if ($request->ajax()) { return view('catalog_ajax', compact('goods')); } |
477c05de1 Каталог страница,... |
75 |
$mf = Good::select('manufacturer')->distinct()->pluck('manufacturer'); |
c5f46e4d5 Таблица просматри... |
76 77 |
return view('catalog', compact('items', 'goods', 'mf', 'articles', 'reviews', 'lookin_good')); |
477c05de1 Каталог страница,... |
78 |
} |
e73374e87 Каталог ajax, адм... |
79 |
public function catalog_detail(Category $category, Request $request) { |
477c05de1 Каталог страница,... |
80 81 |
$items = Category::all(); $title = $category->name; |
e73374e87 Каталог ajax, адм... |
82 |
$goods = Good::query()->where('category_id', '=', $category->id); |
c5f46e4d5 Таблица просматри... |
83 84 85 86 87 |
$articles = News::query()->where('status', '=', 'статья')->paginate(10); $reviews = News::query()->where('status', '=', 'отзыв')->paginate(10); $lookin = Good_Look::query()->orderByDesc('id')->limit(4)->pluck('goods_id') ->toArray(); $lookin_good = Good::query()->whereIn('id', $lookin)->get(); |
e73374e87 Каталог ajax, адм... |
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
if (!empty($request->filter)) { $filter = json_decode($request->filter); if (is_array($filter)) if (count($filter) > 0) $goods = $goods->whereIn('manufacturer', $filter); } if ($request->sort == 'count') { $goods = $goods->orderByDesc('stock_count')->orderByDesc('id'); } if ($request->sort == 'price') { $goods = $goods->orderBy('price')->orderByDesc('id'); } $goods = $goods->paginate(6); if ($request->ajax()) { return view('catalog_ajax', compact('goods')); } |
477c05de1 Каталог страница,... |
109 |
|
e73374e87 Каталог ajax, адм... |
110 |
$mf = Good::select('manufacturer')->distinct()->where('category_id', '=', $category->id)->pluck('manufacturer'); |
c5f46e4d5 Таблица просматри... |
111 112 |
return view('catalog_detail', compact('items', 'category', 'goods', 'title', 'mf', 'articles', 'reviews', 'lookin_good')); |
b80175387 Начальный проект ... |
113 |
} |
295e31db7 Флаги производите... |
114 |
public function good(Good $good) { |
c5f46e4d5 Таблица просматри... |
115 116 117 118 119 |
$looking = new Good_Look(); $looking->goods_id = $good->id; $looking->save(); return view('good', compact('good')); |
b80175387 Начальный проект ... |
120 121 122 123 124 125 |
} public function simple_good() { return view('simple_good'); } } |