Commit 5e41e3567e835d3b38b1869ef037c22616db147f
1 parent
9a5d84dc0d
Exists in
master
Фильтрация и сортировка на странице категории
Showing 8 changed files with 79 additions and 66 deletions Side-by-side Diff
- app/Http/Controllers/MainController.php
- resources/views/ajax/complex/category.blade.php
- resources/views/ajax/complex/test.blade.php
- resources/views/catalog.blade.php
- resources/views/category_catalog.blade.php
- resources/views/js/filter_value.blade.php
- resources/views/part/filter/catalog.blade.php
- resources/views/part/filter/main.blade.php
app/Http/Controllers/MainController.php
... | ... | @@ -187,10 +187,6 @@ class MainController extends Controller |
187 | 187 | return view('favorite'); |
188 | 188 | } |
189 | 189 | |
190 | - public function Category_ajax($cat, Request $request) { | |
191 | - return $cat; | |
192 | - } | |
193 | - | |
194 | 190 | /* |
195 | 191 | * Категории каталога Аренда/Продажа/Бизнес |
196 | 192 | */ |
... | ... | @@ -217,7 +213,7 @@ class MainController extends Controller |
217 | 213 | $houses = House::with('areas')-> |
218 | 214 | where('format_house', '=', $format_house); |
219 | 215 | //->appends(request()->query()); |
220 | - /* | |
216 | + | |
221 | 217 | if (!empty($request->area)) { |
222 | 218 | $houses = $houses->where('area_id', '=', $request->area); |
223 | 219 | } |
... | ... | @@ -250,7 +246,7 @@ class MainController extends Controller |
250 | 246 | $houses = $houses->where('address', 'LIKE', "%".$request->address."%"); |
251 | 247 | } |
252 | 248 | |
253 | - if (!empty($request->sort_price)) { | |
249 | + if (isset($request->sort_price)) { | |
254 | 250 | switch ($request->sort_price) { |
255 | 251 | case 1: $houses = $houses->orderBy('price');break; |
256 | 252 | case 2: $houses = $houses->orderByDesc('price');break; |
... | ... | @@ -260,15 +256,16 @@ class MainController extends Controller |
260 | 256 | case 2: $houses = $houses->orderBy('created_at');break; |
261 | 257 | } |
262 | 258 | switch ($request->sort_area) { |
263 | - case 1: $houses = $houses->orderByDesc('area')->get();break; | |
264 | - case 2: $houses = $houses->orderBy('area')->get();break; | |
259 | + case 1: $houses = $houses->orderByDesc('area');break; | |
260 | + case 2: $houses = $houses->orderBy('area');break; | |
265 | 261 | } |
262 | + | |
266 | 263 | } else { |
267 | 264 | $houses = $houses->orderBy('price')-> |
268 | 265 | orderByDesc('created_at')-> |
269 | 266 | orderByDesc('area'); |
270 | 267 | } |
271 | -*/ | |
268 | + | |
272 | 269 | $houses = $houses->paginate(4); |
273 | 270 | |
274 | 271 | if ($request->ajax()) { |
resources/views/ajax/complex/category.blade.php
resources/views/ajax/complex/test.blade.php
resources/views/catalog.blade.php
... | ... | @@ -5,8 +5,10 @@ |
5 | 5 | @endsection |
6 | 6 | |
7 | 7 | @section('custom_js') |
8 | + @include('js.filter_value'); | |
8 | 9 | <script> |
9 | - $(window).load(function() { | |
10 | + /* | |
11 | + $(window).load(function() { | |
10 | 12 | var url_str = "<?=url()->full();?>"; |
11 | 13 | var url = new URL(url_str); |
12 | 14 | var searchParams = new URLSearchParams(url.search.substring(1)); |
... | ... | @@ -55,7 +57,7 @@ |
55 | 57 | }); |
56 | 58 | } |
57 | 59 | }); |
58 | - | |
60 | +*/ | |
59 | 61 | $(document).on('click', '.js_sort_group_item', function() { |
60 | 62 | var val = $(this).data('val'); |
61 | 63 | var sort_price_val = ''; |
resources/views/category_catalog.blade.php
... | ... | @@ -5,57 +5,8 @@ |
5 | 5 | @endsection |
6 | 6 | |
7 | 7 | @section('custom_js') |
8 | - <script> | |
9 | - $(window).load(function() { | |
10 | - var url_str = "<?=url()->full();?>"; | |
11 | - var url = new URL(url_str); | |
12 | - var searchParams = new URLSearchParams(url.search.substring(1)); | |
13 | - | |
14 | - var area = searchParams.get("area"), | |
15 | - type_area = searchParams.get("type_area"), | |
16 | - format_area= searchParams.get("format_area"), | |
17 | - address= searchParams.get("address"); | |
18 | - | |
19 | - var area_name = $('#area_name'); | |
20 | - var type_area_name = $('#type_area_name'); | |
21 | - var format_area_name = $('#format_area_name'); | |
22 | - var address_name = $('#address'); | |
23 | - | |
24 | - if ((area !== "") || (type_area !== "") || (format_area !== "") || (address !== "")) | |
25 | - { | |
26 | - $.ajax({ | |
27 | - type: "GET", | |
28 | - url: "{{ route('catalog_ajax_filter') }}", | |
29 | - data: "area=" + area + "&type_area=" + type_area + "&format_area=" + format_area + "&address=" + address + "", | |
30 | - success: function (data) { | |
31 | - console.log('Фильтры данных были переданы '); | |
32 | - data = JSON.parse(data); | |
33 | - console.log(data); | |
34 | - | |
35 | - if (area !== "") { | |
36 | - area_name.html(data[0]); | |
37 | - } | |
38 | - if (type_area !== "") { | |
39 | - type_area_name.html(data[1]); | |
40 | - } | |
41 | - if (format_area !== "") { | |
42 | - format_area_name.html(data[2]); | |
43 | - } | |
44 | - if (address !== "") { | |
45 | - address_name.html(data[3]); | |
46 | - } | |
47 | - | |
48 | - }, | |
49 | - headers: { | |
50 | - 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') | |
51 | - }, | |
52 | - error: function (data) { | |
53 | - console.log('Error: ' + data); | |
54 | - } | |
55 | - }); | |
56 | - } | |
57 | - }); | |
58 | - | |
8 | + @include('js.filter_value'); | |
9 | + <script> | |
59 | 10 | $(document).on('click', '.js_sort_group_item', function() { |
60 | 11 | var val = $(this).data('val'); |
61 | 12 | var sort_price_val = ''; |
... | ... | @@ -93,7 +44,7 @@ |
93 | 44 | "&area_m2_min=<? if (isset($_GET['area_m2_min'])) echo $_GET['area_m2_min'];?>&area_m2_max=<? if (isset($_GET['area_m2_max'])) echo $_GET['area_m2_max'];?>"+ |
94 | 45 | "&price_min=<? if (isset($_GET['price_min'])) echo $_GET['price_min'];?>&price_max=<? if (isset($_GET['price_max'])) echo $_GET['price_max'];?>&address=<? if (isset($_GET['address'])) echo $_GET['address'];?>", |
95 | 46 | success: function(data) { |
96 | - console.log('Успешно обновлены данные таблиц '+data); | |
47 | + console.log('Успешно обновлены данные таблиц!!!!!!!!!! '); | |
97 | 48 | $('#block_ajax').html(data); |
98 | 49 | }, |
99 | 50 | headers: { |
resources/views/js/filter_value.blade.php
... | ... | @@ -0,0 +1,58 @@ |
1 | +<script> | |
2 | + $(window).load(function() { | |
3 | + var url_str = "<?=url()->full();?>"; | |
4 | + var url = new URL(url_str); | |
5 | + var searchParams = new URLSearchParams(url.search.substring(1)); | |
6 | + | |
7 | + var area = searchParams.get("area"), | |
8 | + type_area = searchParams.get("type_area"), | |
9 | + format_area= searchParams.get("format_area"), | |
10 | + address= searchParams.get("address"); | |
11 | + | |
12 | + var area_name = $('#area_name'); | |
13 | + var type_area_name = $('#type_area_name'); | |
14 | + var format_area_name = $('#format_area_name'); | |
15 | + var address_name = $('#address'); | |
16 | + | |
17 | + var area_input = $('#area'); | |
18 | + var type_area_input = $('#type_area'); | |
19 | + var format_area_input = $('#format_area'); | |
20 | + | |
21 | + if ((area !== "") || (type_area !== "") || (format_area !== "") || (address !== "")) | |
22 | + { | |
23 | + $.ajax({ | |
24 | + type: "GET", | |
25 | + url: "{{ route('catalog_ajax_filter') }}", | |
26 | + data: "area=" + area + "&type_area=" + type_area + "&format_area=" + format_area + "&address=" + address + "", | |
27 | + success: function (data) { | |
28 | + console.log('Фильтры данных были переданы '); | |
29 | + data = JSON.parse(data); | |
30 | + console.log(data); | |
31 | + | |
32 | + if (area !== "") { | |
33 | + area_name.html(data[0]); | |
34 | + area_input.val(area); | |
35 | + } | |
36 | + if (type_area !== "") { | |
37 | + type_area_name.html(data[1]); | |
38 | + type_area_input.val(type_area); | |
39 | + } | |
40 | + if (format_area !== "") { | |
41 | + format_area_name.html(data[2]); | |
42 | + format_area_input.val(format_area); | |
43 | + } | |
44 | + if (address !== "") { | |
45 | + address_name.html(data[3]); | |
46 | + } | |
47 | + | |
48 | + }, | |
49 | + headers: { | |
50 | + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') | |
51 | + }, | |
52 | + error: function (data) { | |
53 | + console.log('Error: ' + data); | |
54 | + } | |
55 | + }); | |
56 | + } | |
57 | + }); | |
58 | +</script> |
resources/views/part/filter/catalog.blade.php
... | ... | @@ -103,7 +103,7 @@ |
103 | 103 | <div class="hero-search__buttons"> |
104 | 104 | <a class="hero-search__btn btn btn--white js_hero_search_btn" href="{{ route('maps') }}">Показать на карте</a> |
105 | 105 | <button type="submit" class="hero-search__btn btn btn--main js_hero_search_btn"> |
106 | - {{ session()->get('message') }} | |
106 | + Искать | |
107 | 107 | </button> |
108 | 108 | </div> |
109 | 109 | </div> |
resources/views/part/filter/main.blade.php
... | ... | @@ -97,7 +97,7 @@ |
97 | 97 | <div class="hero-search__buttons"> |
98 | 98 | <a class="hero-search__btn btn btn--white js_hero_search_btn" href="{{ route('maps') }}">Показать на карте</a> |
99 | 99 | <button type="submit" class="hero-search__btn btn btn--main js_hero_search_btn"> |
100 | - Искать<? //session()->get('message')?> | |
100 | + Искать | |
101 | 101 | </button> |
102 | 102 | </div> |
103 | 103 | </div> |