MainController.php
3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace App\Http\Controllers;
use App\Models\Banner;
use App\Models\Category;
use App\Models\Good;
use App\Models\News;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Session\Storage;
class MainController extends Controller
{
// Главная страница
public function index(Request $request) {
$banners = Banner::query()->orderBy('id')->get();
$category = Category::query()->where('parent_id', '>', '0')->orderBy('id')->get();
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'));
}
$news = News::query()->where('status', '=', 'новость')->orderByDesc('id')->paginate(3);
return view('index',
compact('banners', 'category', 'goods', 'news'));
}
public function about_company() {
return view('company');
}
public function catalog(Request $request) {
$items = Category::all();
$goods = Good::query();
$articles = News::query()->where('status', '=', 'статья')->paginate(10);
$reviews = News::query()->where('status', '=', 'отзыв')->paginate(3);
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'));
}
$mf = Good::select('manufacturer')->distinct()->pluck('manufacturer');
return view('catalog', compact('items', 'goods', 'mf', 'articles', 'reviews'));
}
public function catalog_detail(Category $category, Request $request) {
$items = Category::all();
$title = $category->name;
$goods = Good::query()->where('category_id', '=', $category->id);
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'));
}
$mf = Good::select('manufacturer')->distinct()->where('category_id', '=', $category->id)->pluck('manufacturer');
return view('catalog_detail', compact('items', 'category', 'goods', 'title', 'mf'));
}
public function good(Good $good) {
return view('good');
}
public function simple_good() {
return view('simple_good');
}
}