Commit 59d4ce857ef6179c02f3075858d49bb4028a2f87
1 parent
28e5481503
Exists in
master
Рефакторинг кода, исправление ошибки фильтра с ценами, исправление ошибки с избранными
Showing 6 changed files with 61 additions and 334 deletions Side-by-side Diff
app/Classes/FilterData.php
... | ... | @@ -17,7 +17,7 @@ class FilterData |
17 | 17 | public function apply() { |
18 | 18 | foreach ($this->filters() as $filter => $value) { |
19 | 19 | if (method_exists($this, $filter)) { |
20 | - $this->filter($value); | |
20 | + if (!empty($value)) $this->$filter($value); | |
21 | 21 | } |
22 | 22 | } |
23 | 23 | return $this->builder; |
... | ... | @@ -36,23 +36,32 @@ class FilterData |
36 | 36 | } |
37 | 37 | |
38 | 38 | public function area_m2_min($value) { |
39 | - return $this->builder->where('area', '>', $value); | |
39 | + $value = str_replace("+", "", $value); | |
40 | + $value = str_replace(' ', '', $value); | |
41 | + if ($value) return $this->builder->where('area', '>', $value); | |
40 | 42 | } |
41 | 43 | |
42 | 44 | public function area_m2_max($value) { |
43 | - return $this->builder->where('area', '<', $value); | |
45 | + $value = str_replace("+", "", $value); | |
46 | + $value = str_replace(' ', '', $value); | |
47 | + if ($value) return $this->builder->where('area', '<', $value); | |
44 | 48 | } |
45 | 49 | |
46 | 50 | public function price_min($value) { |
47 | - return $this->builder->where('price', '>', $value); | |
51 | + $value = str_replace("+", "", $value); | |
52 | + $value = str_replace(' ', '', $value); | |
53 | + | |
54 | + if ($value) return $this->builder->where('price', '>', $value); | |
48 | 55 | } |
49 | 56 | |
50 | 57 | public function price_max($value) { |
51 | - return $this->builder->where('price', '<', $value); | |
58 | + $value = str_replace("+", "", $value); | |
59 | + $value = str_replace(' ', '', $value); | |
60 | + if ($value) return $this->builder->where('price', '<', $value); | |
52 | 61 | } |
53 | 62 | |
54 | 63 | public function address($value) { |
55 | - return $this->builder->where('address', 'LIKE', "%".$value."%"); | |
64 | + if ($value) return $this->builder->where('address', 'LIKE', "%".$value."%"); | |
56 | 65 | } |
57 | 66 | |
58 | 67 | public function filters() { |
app/Classes/SortData.php
app/Http/Controllers/MainController.php
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | |
3 | 3 | namespace App\Http\Controllers; |
4 | 4 | |
5 | +use App\Classes\SortData; | |
5 | 6 | use App\Http\Requests\EmailRequest; |
6 | 7 | use App\Http\Requests\FooterFeedbackRequest; |
7 | 8 | use App\Models\Area; |
... | ... | @@ -73,18 +74,8 @@ class MainController extends Controller |
73 | 74 | where('format_house', '=', 'Аренда'); |
74 | 75 | |
75 | 76 | if ($request->view == 'arenda') { |
76 | - switch ($request->sort_price) { | |
77 | - case 1: $house_arenda = $house_arenda->orderBy('price');break; | |
78 | - case 2: $house_arenda = $house_arenda->orderByDesc('price');break; | |
79 | - } | |
80 | - switch ($request->sort_new) { | |
81 | - case 1: $house_arenda = $house_arenda->orderByDesc('created_at');break; | |
82 | - case 2: $house_arenda = $house_arenda->orderBy('created_at');break; | |
83 | - } | |
84 | - switch ($request->sort_area) { | |
85 | - case 1: $house_arenda = $house_arenda->orderByDesc('area')->get();break; | |
86 | - case 2: $house_arenda = $house_arenda->orderBy('area')->get();break; | |
87 | - } | |
77 | + $house_arenda = (new SortData($house_arenda, $request))->apply()->get(); | |
78 | + | |
88 | 79 | } else { |
89 | 80 | $house_arenda = $house_arenda->orderBy('price')-> |
90 | 81 | orderByDesc('created_at')-> |
... | ... | @@ -97,18 +88,8 @@ class MainController extends Controller |
97 | 88 | where('format_house', '=', 'Продажа'); |
98 | 89 | |
99 | 90 | if ($request->view == 'prodaja') { |
100 | - switch ($request->sort_price) { | |
101 | - case 1: $house_prodaja = $house_prodaja->orderBy('price');break; | |
102 | - case 2: $house_prodaja = $house_prodaja->orderByDesc('price');break; | |
103 | - } | |
104 | - switch ($request->sort_new) { | |
105 | - case 1: $house_prodaja = $house_prodaja->orderByDesc('created_at');break; | |
106 | - case 2: $house_prodaja = $house_prodaja->orderBy('created_at');break; | |
107 | - } | |
108 | - switch ($request->sort_area) { | |
109 | - case 1: $house_prodaja = $house_prodaja->orderByDesc('area')->get();break; | |
110 | - case 2: $house_prodaja = $house_prodaja->orderBy('area')->get();break; | |
111 | - } | |
91 | + $house_prodaja = (new SortData($house_prodaja, $request))->apply()->get(); | |
92 | + | |
112 | 93 | } else { |
113 | 94 | $house_prodaja = $house_prodaja->orderBy('price')-> |
114 | 95 | orderByDesc('created_at')-> |
... | ... | @@ -122,18 +103,8 @@ class MainController extends Controller |
122 | 103 | //orderByDesc('created_at')->get(); |
123 | 104 | |
124 | 105 | if ($request->view == 'bissnes') { |
125 | - switch ($request->sort_price) { | |
126 | - case 1: $house_bissnes = $house_bissnes->orderBy('price');break; | |
127 | - case 2: $house_bissnes = $house_bissnes->orderByDesc('price');break; | |
128 | - } | |
129 | - switch ($request->sort_new) { | |
130 | - case 1: $house_bissnes = $house_bissnes->orderByDesc('created_at');break; | |
131 | - case 2: $house_bissnes = $house_bissnes->orderBy('created_at');break; | |
132 | - } | |
133 | - switch ($request->sort_area) { | |
134 | - case 1: $house_bissnes = $house_bissnes->orderByDesc('area')->get();break; | |
135 | - case 2: $house_bissnes = $house_bissnes->orderBy('area')->get();break; | |
136 | - } | |
106 | + $house_bissnes = (new SortData($house_bissnes, $request))->apply()->get(); | |
107 | + | |
137 | 108 | } else { |
138 | 109 | $house_bissnes = $house_bissnes->orderBy('price')-> |
139 | 110 | orderByDesc('created_at')-> |
... | ... | @@ -147,18 +118,8 @@ class MainController extends Controller |
147 | 118 | //orderByDesc('created_at')->get(); |
148 | 119 | |
149 | 120 | if ($request->view == 'arendovannie') { |
150 | - switch ($request->sort_price) { | |
151 | - case 1: $house_arendovannie = $house_arendovannie->orderBy('price');break; | |
152 | - case 2: $house_arendovannie = $house_arendovannie->orderByDesc('price');break; | |
153 | - } | |
154 | - switch ($request->sort_new) { | |
155 | - case 1: $house_arendovannie = $house_arendovannie->orderByDesc('created_at');break; | |
156 | - case 2: $house_arendovannie = $house_arendovannie->orderBy('created_at');break; | |
157 | - } | |
158 | - switch ($request->sort_area) { | |
159 | - case 1: $house_arendovannie = $house_arendovannie->orderByDesc('area')->get();break; | |
160 | - case 2: $house_arendovannie = $house_arendovannie->orderBy('area')->get();break; | |
161 | - } | |
121 | + $house_arendovannie = (new SortData($house_arendovannie, $request))->apply()->get(); | |
122 | + | |
162 | 123 | } else { |
163 | 124 | $house_arendovannie = $house_arendovannie->orderBy('price')-> |
164 | 125 | orderByDesc('created_at')-> |
... | ... | @@ -286,18 +247,8 @@ class MainController extends Controller |
286 | 247 | $houses = House::with('areas')->whereIn('id', $Arr); |
287 | 248 | |
288 | 249 | if (isset($request->sort_price)) { |
289 | - switch ($request->sort_price) { | |
290 | - case 1: $houses = $houses->orderBy('price');break; | |
291 | - case 2: $houses = $houses->orderByDesc('price');break; | |
292 | - } | |
293 | - switch ($request->sort_new) { | |
294 | - case 1: $houses = $houses->orderByDesc('created_at');break; | |
295 | - case 2: $houses = $houses->orderBy('created_at');break; | |
296 | - } | |
297 | - switch ($request->sort_area) { | |
298 | - case 1: $houses = $houses->orderByDesc('area');break; | |
299 | - case 2: $houses = $houses->orderBy('area');break; | |
300 | - } | |
250 | + $houses = (new SortData($houses, $request))->apply(); | |
251 | + | |
301 | 252 | |
302 | 253 | } else { |
303 | 254 | $houses = $houses->orderBy('price')-> |
... | ... | @@ -320,7 +271,7 @@ class MainController extends Controller |
320 | 271 | } |
321 | 272 | |
322 | 273 | /* |
323 | - * Категории каталога Аренда/Продажа/Бизнес | |
274 | + * Категории каталога Аренда/Продажа/Бизнес/Арендованные | |
324 | 275 | */ |
325 | 276 | public function Category($cat, Request $request) { |
326 | 277 | switch ($cat) { |
... | ... | @@ -336,6 +287,10 @@ class MainController extends Controller |
336 | 287 | $title = "Арендый бизнес"; |
337 | 288 | $format_house = 'Бизнес'; |
338 | 289 | break; |
290 | + case 'arendovannie': | |
291 | + $title = "Арендованные"; | |
292 | + $format_house = 'Арендованные'; | |
293 | + break; | |
339 | 294 | default: |
340 | 295 | $title = "Аренда торговых помещениий"; |
341 | 296 | $format_house = 'Аренда'; |
... | ... | @@ -346,51 +301,11 @@ class MainController extends Controller |
346 | 301 | where('format_house', '=', $format_house); |
347 | 302 | //->appends(request()->query()); |
348 | 303 | |
349 | - if (!empty($request->area)) { | |
350 | - $houses = $houses->where('area_id', '=', $request->area); | |
351 | - } | |
352 | - // условия поиска по типу недвижимости | |
353 | - if (!empty($request->type_area)) { | |
354 | - $houses = $houses->where('type_area_id', '=', $request->type_area); | |
355 | - } | |
356 | - // условия поиска по формату недвижимости | |
357 | - if (!empty($request->format_area)) { | |
358 | - $houses = $houses->where('format_area_id', '=', $request->format_area); | |
359 | - } | |
360 | - // условия поиска по площади - минимальная площадь | |
361 | - if (!empty($request->area_m2_min)) { | |
362 | - $houses = $houses->where('area', '>', $request->area_m2_min); | |
363 | - } | |
364 | - // условия поиска по площади - максимальная площадь | |
365 | - if (!empty($request->area_m2_max)) { | |
366 | - $houses = $houses->where('area', '<', $request->area_m2_max); | |
367 | - } | |
368 | - // условия поиска по цене - минимальная цена | |
369 | - if (!empty($request->price_min)) { | |
370 | - $houses = $houses->where('price', '>', $request->price_min); | |
371 | - } | |
372 | - // условия поиска по цене - максимальная цена | |
373 | - if (!empty($request->price_max)) { | |
374 | - $houses = $houses->where('price', '<', $request->price_max); | |
375 | - } | |
376 | - // условия поиска по адресу | |
377 | - if (!empty($request->address)) { | |
378 | - $houses = $houses->where('address', 'LIKE', "%".$request->address."%"); | |
379 | - } | |
304 | + $houses = (new FilterData($houses, $request))->apply(); | |
380 | 305 | |
381 | 306 | if (isset($request->sort_price)) { |
382 | - switch ($request->sort_price) { | |
383 | - case 1: $houses = $houses->orderBy('price');break; | |
384 | - case 2: $houses = $houses->orderByDesc('price');break; | |
385 | - } | |
386 | - switch ($request->sort_new) { | |
387 | - case 1: $houses = $houses->orderByDesc('created_at');break; | |
388 | - case 2: $houses = $houses->orderBy('created_at');break; | |
389 | - } | |
390 | - switch ($request->sort_area) { | |
391 | - case 1: $houses = $houses->orderByDesc('area');break; | |
392 | - case 2: $houses = $houses->orderBy('area');break; | |
393 | - } | |
307 | + $houses = (new SortData($houses, $request))->apply(); | |
308 | + | |
394 | 309 | |
395 | 310 | } else { |
396 | 311 | $houses = $houses->orderBy('price')-> |
... | ... | @@ -431,55 +346,10 @@ class MainController extends Controller |
431 | 346 | where('format_house', '=', 'Аренда'); |
432 | 347 | // условия поиска по объектам комплексов |
433 | 348 | |
434 | - //$house_arenda = (new FilterData($house_arenda, $request))->apply(); | |
435 | - | |
436 | - | |
437 | - if (!empty($request->area)) { | |
438 | - $house_arenda = $house_arenda->where('area_id', '=', $request->area); | |
439 | - } | |
440 | - // условия поиска по типу недвижимости | |
441 | - if (!empty($request->type_area)) { | |
442 | - $house_arenda = $house_arenda->where('type_area_id', '=', $request->type_area); | |
443 | - } | |
444 | - // условия поиска по формату недвижимости | |
445 | - if (!empty($request->format_area)) { | |
446 | - $house_arenda = $house_arenda->where('format_area_id', '=', $request->format_area); | |
447 | - } | |
448 | - // условия поиска по площади - минимальная площадь | |
449 | - if (!empty($request->area_m2_min)) { | |
450 | - $house_arenda = $house_arenda->where('area', '>', $request->area_m2_min); | |
451 | - } | |
452 | - // условия поиска по площади - максимальная площадь | |
453 | - if (!empty($request->area_m2_max)) { | |
454 | - $house_arenda = $house_arenda->where('area', '<', $request->area_m2_max); | |
455 | - } | |
456 | - // условия поиска по цене - минимальная цена | |
457 | - if (!empty($request->price_min)) { | |
458 | - $house_arenda = $house_arenda->where('price', '>', $request->price_min); | |
459 | - } | |
460 | - // условия поиска по цене - максимальная цена | |
461 | - if (!empty($request->price_max)) { | |
462 | - $house_arenda = $house_arenda->where('price', '<', $request->price_max); | |
463 | - } | |
464 | - // условия поиска по адресу | |
465 | - if (!empty($request->address)) { | |
466 | - $house_arenda = $house_arenda->where('address', 'LIKE', "%".$request->address."%"); | |
467 | - } | |
468 | - | |
349 | + $house_arenda = (new FilterData($house_arenda, $request))->apply(); | |
469 | 350 | |
470 | 351 | if ($request->view == 'arenda') { |
471 | - switch ($request->sort_price) { | |
472 | - case 1: $house_arenda = $house_arenda->orderBy('price');break; | |
473 | - case 2: $house_arenda = $house_arenda->orderByDesc('price');break; | |
474 | - } | |
475 | - switch ($request->sort_new) { | |
476 | - case 1: $house_arenda = $house_arenda->orderByDesc('created_at');break; | |
477 | - case 2: $house_arenda = $house_arenda->orderBy('created_at');break; | |
478 | - } | |
479 | - switch ($request->sort_area) { | |
480 | - case 1: $house_arenda = $house_arenda->orderByDesc('area')->get();break; | |
481 | - case 2: $house_arenda = $house_arenda->orderBy('area')->get();break; | |
482 | - } | |
352 | + $house_arenda = (new SortData($house_arenda, $request))->apply()->get(); | |
483 | 353 | } else { |
484 | 354 | $house_arenda = $house_arenda->orderBy('price')-> |
485 | 355 | orderByDesc('created_at')-> |
... | ... | @@ -490,52 +360,11 @@ class MainController extends Controller |
490 | 360 | $house_prodaja = House::with('areas')-> |
491 | 361 | where('format_house', '=', 'Продажа'); |
492 | 362 | |
493 | - // условия поиска по объектам комплексов | |
494 | - if (!empty($request->area)) { | |
495 | - $house_prodaja = $house_prodaja->where('area_id', '=', $request->area); | |
496 | - } | |
497 | - // условия поиска по типу недвижимости | |
498 | - if (!empty($request->type_area)) { | |
499 | - $house_prodaja = $house_prodaja->where('type_area_id', '=', $request->type_area); | |
500 | - } | |
501 | - // условия поиска по формату недвижимости | |
502 | - if (!empty($request->format_area)) { | |
503 | - $house_prodaja = $house_prodaja->where('format_area_id', '=', $request->format_area); | |
504 | - } | |
505 | - // условия поиска по площади - минимальная площадь | |
506 | - if (!empty($request->area_m2_min)) { | |
507 | - $house_prodaja = $house_prodaja->where('area', '>', $request->area_m2_min); | |
508 | - } | |
509 | - // условия поиска по площади - максимальная площадь | |
510 | - if (!empty($request->area_m2_max)) { | |
511 | - $house_prodaja = $house_prodaja->where('area', '<', $request->area_m2_max); | |
512 | - } | |
513 | - // условия поиска по цене - минимальная цена | |
514 | - if (!empty($request->price_min)) { | |
515 | - $house_prodaja = $house_prodaja->where('price', '>', $request->price_min); | |
516 | - } | |
517 | - // условия поиска по цене - максимальная цена | |
518 | - if (!empty($request->price_max)) { | |
519 | - $house_prodaja = $house_prodaja->where('price', '<', $request->price_max); | |
520 | - } | |
521 | - // условия поиска по адресу | |
522 | - if (!empty($request->address)) { | |
523 | - $house_prodaja = $house_prodaja->where('address', 'LIKE', "%".$request->address."%"); | |
524 | - } | |
363 | + $house_prodaja = (new FilterData($house_prodaja, $request))->apply(); | |
525 | 364 | |
526 | 365 | if ($request->view == 'prodaja') { |
527 | - switch ($request->sort_price) { | |
528 | - case 1: $house_prodaja = $house_prodaja->orderBy('price');break; | |
529 | - case 2: $house_prodaja = $house_prodaja->orderByDesc('price');break; | |
530 | - } | |
531 | - switch ($request->sort_new) { | |
532 | - case 1: $house_prodaja = $house_prodaja->orderByDesc('created_at');break; | |
533 | - case 2: $house_prodaja = $house_prodaja->orderBy('created_at');break; | |
534 | - } | |
535 | - switch ($request->sort_area) { | |
536 | - case 1: $house_prodaja = $house_prodaja->orderByDesc('area')->get();break; | |
537 | - case 2: $house_prodaja = $house_prodaja->orderBy('area')->get();break; | |
538 | - } | |
366 | + $house_prodaja = (new SortData($house_prodaja, $request))->apply()->get(); | |
367 | + | |
539 | 368 | } else { |
540 | 369 | $house_prodaja = $house_prodaja->orderBy('price')-> |
541 | 370 | orderByDesc('created_at')-> |
... | ... | @@ -547,52 +376,11 @@ class MainController extends Controller |
547 | 376 | where('format_house', '=', 'Бизнес'); |
548 | 377 | //orderByDesc('created_at')->get(); |
549 | 378 | |
550 | - // условия поиска по объектам комплексов | |
551 | - if (!empty($request->area)) { | |
552 | - $house_bissnes = $house_bissnes->where('area_id', '=', $request->area); | |
553 | - } | |
554 | - // условия поиска по типу недвижимости | |
555 | - if (!empty($request->type_area)) { | |
556 | - $house_bissnes = $house_bissnes->where('type_area_id', '=', $request->type_area); | |
557 | - } | |
558 | - // условия поиска по формату недвижимости | |
559 | - if (!empty($request->format_area)) { | |
560 | - $house_bissnes = $house_bissnes->where('format_area_id', '=', $request->format_area); | |
561 | - } | |
562 | - // условия поиска по площади - минимальная площадь | |
563 | - if (!empty($request->area_m2_min)) { | |
564 | - $house_bissnes = $house_bissnes->where('area', '>', $request->area_m2_min); | |
565 | - } | |
566 | - // условия поиска по площади - максимальная площадь | |
567 | - if (!empty($request->area_m2_max)) { | |
568 | - $house_bissnes = $house_bissnes->where('area', '<', $request->area_m2_max); | |
569 | - } | |
570 | - // условия поиска по цене - минимальная цена | |
571 | - if (!empty($request->price_min)) { | |
572 | - $house_bissnes = $house_bissnes->where('price', '>', $request->price_min); | |
573 | - } | |
574 | - // условия поиска по цене - максимальная цена | |
575 | - if (!empty($request->price_max)) { | |
576 | - $house_bissnes = $house_bissnes->where('price', '<', $request->price_max); | |
577 | - } | |
578 | - // условия поиска по адресу | |
579 | - if (!empty($request->address)) { | |
580 | - $house_bissnes = $house_bissnes->where('address', 'LIKE', "%".$request->address."%"); | |
581 | - } | |
379 | + $house_bissnes = (new FilterData($house_bissnes, $request))->apply(); | |
582 | 380 | |
583 | 381 | if ($request->view == 'bissnes') { |
584 | - switch ($request->sort_price) { | |
585 | - case 1: $house_bissnes = $house_bissnes->orderBy('price');break; | |
586 | - case 2: $house_bissnes = $house_bissnes->orderByDesc('price');break; | |
587 | - } | |
588 | - switch ($request->sort_new) { | |
589 | - case 1: $house_bissnes = $house_bissnes->orderByDesc('created_at');break; | |
590 | - case 2: $house_bissnes = $house_bissnes->orderBy('created_at');break; | |
591 | - } | |
592 | - switch ($request->sort_area) { | |
593 | - case 1: $house_bissnes = $house_bissnes->orderByDesc('area')->get();break; | |
594 | - case 2: $house_bissnes = $house_bissnes->orderBy('area')->get();break; | |
595 | - } | |
382 | + $house_bissnes = (new SortData($house_bissnes, $request))->apply()->get(); | |
383 | + | |
596 | 384 | } else { |
597 | 385 | $house_bissnes = $house_bissnes->orderBy('price')-> |
598 | 386 | orderByDesc('created_at')-> |
... | ... | @@ -604,52 +392,11 @@ class MainController extends Controller |
604 | 392 | where('format_house', '=', 'Арендованные'); |
605 | 393 | //orderByDesc('created_at')->get(); |
606 | 394 | |
607 | - // условия поиска по объектам комплексов | |
608 | - if (!empty($request->area)) { | |
609 | - $house_arendovannie = $house_arendovannie->where('area_id', '=', $request->area); | |
610 | - } | |
611 | - // условия поиска по типу недвижимости | |
612 | - if (!empty($request->type_area)) { | |
613 | - $house_arendovannie = $house_arendovannie->where('type_area_id', '=', $request->type_area); | |
614 | - } | |
615 | - // условия поиска по формату недвижимости | |
616 | - if (!empty($request->format_area)) { | |
617 | - $house_arendovannie = $house_arendovannie->where('format_area_id', '=', $request->format_area); | |
618 | - } | |
619 | - // условия поиска по площади - минимальная площадь | |
620 | - if (!empty($request->area_m2_min)) { | |
621 | - $house_arendovannie = $house_arendovannie->where('area', '>', $request->area_m2_min); | |
622 | - } | |
623 | - // условия поиска по площади - максимальная площадь | |
624 | - if (!empty($request->area_m2_max)) { | |
625 | - $house_arendovannie = $house_arendovannie->where('area', '<', $request->area_m2_max); | |
626 | - } | |
627 | - // условия поиска по цене - минимальная цена | |
628 | - if (!empty($request->price_min)) { | |
629 | - $house_arendovannie = $house_arendovannie->where('price', '>', $request->price_min); | |
630 | - } | |
631 | - // условия поиска по цене - максимальная цена | |
632 | - if (!empty($request->price_max)) { | |
633 | - $house_arendovannie = $house_arendovannie->where('price', '<', $request->price_max); | |
634 | - } | |
635 | - // условия поиска по адресу | |
636 | - if (!empty($request->address)) { | |
637 | - $house_arendovannie = $house_arendovannie->where('address', 'LIKE', "%".$request->address."%"); | |
638 | - } | |
395 | + $house_arendovannie = (new FilterData($house_arendovannie, $request))->apply(); | |
639 | 396 | |
640 | 397 | if ($request->view == 'arendovannie') { |
641 | - switch ($request->sort_price) { | |
642 | - case 1: $house_arendovannie = $house_arendovannie->orderBy('price');break; | |
643 | - case 2: $house_arendovannie = $house_arendovannie->orderByDesc('price');break; | |
644 | - } | |
645 | - switch ($request->sort_new) { | |
646 | - case 1: $house_arendovannie = $house_arendovannie->orderByDesc('created_at');break; | |
647 | - case 2: $house_arendovannie = $house_arendovannie->orderBy('created_at');break; | |
648 | - } | |
649 | - switch ($request->sort_area) { | |
650 | - case 1: $house_arendovannie = $house_arendovannie->orderByDesc('area')->get();break; | |
651 | - case 2: $house_arendovannie = $house_arendovannie->orderBy('area')->get();break; | |
652 | - } | |
398 | + $house_arendovannie = (new SortData($house_arendovannie, $request))->apply()->get(); | |
399 | + | |
653 | 400 | } else { |
654 | 401 | $house_arendovannie = $house_arendovannie->orderBy('price')-> |
655 | 402 | orderByDesc('created_at')-> |
... | ... | @@ -712,39 +459,7 @@ class MainController extends Controller |
712 | 459 | if (empty($input)) { |
713 | 460 | |
714 | 461 | } else { |
715 | - | |
716 | - // условия поиска по объектам комплексов | |
717 | - if (!empty($request->area)) { | |
718 | - $houses = $houses->where('area_id', '=', $request->area); | |
719 | - } | |
720 | - // условия поиска по типу недвижимости | |
721 | - if (!empty($request->type_area)) { | |
722 | - $houses = $houses->where('type_area_id', '=', $request->type_area); | |
723 | - } | |
724 | - // условия поиска по формату недвижимости | |
725 | - if (!empty($request->format_area)) { | |
726 | - $houses = $houses->where('format_area_id', '=', $request->format_area); | |
727 | - } | |
728 | - // условия поиска по площади - минимальная площадь | |
729 | - if (!empty($request->area_m2_min)) { | |
730 | - $houses = $houses->where('area', '>', $request->area_m2_min); | |
731 | - } | |
732 | - // условия поиска по площади - максимальная площадь | |
733 | - if (!empty($request->area_m2_max)) { | |
734 | - $houses = $houses->where('area', '<', $request->area_m2_max); | |
735 | - } | |
736 | - // условия поиска по цене - минимальная цена | |
737 | - if (!empty($request->price_min)) { | |
738 | - $houses = $houses->where('price', '>', $request->price_min); | |
739 | - } | |
740 | - // условия поиска по цене - максимальная цена | |
741 | - if (!empty($request->price_max)) { | |
742 | - $houses = $houses->where('price', '<', $request->price_max); | |
743 | - } | |
744 | - // условия поиска по адресу | |
745 | - if (!empty($request->address)) { | |
746 | - $houses = $houses->where('address', 'LIKE', "%".$request->address."%"); | |
747 | - } | |
462 | + $houses = (new FilterData($houses, $request))->apply(); | |
748 | 463 | } |
749 | 464 | |
750 | 465 | $houses = $houses->orderByDesc('id')->get(); |
resources/views/catalog.blade.php
... | ... | @@ -162,7 +162,7 @@ |
162 | 162 | <div class="container"> |
163 | 163 | <div class="slider__wrap"> |
164 | 164 | <div class="slider__top"> |
165 | - <h2 class="slider__title title">Аренда торговых помещений</h2><a class="slider__more" href="#">Показать все объекты</a> | |
165 | + <h2 class="slider__title title">Аренда торговых помещений</h2><a class="slider__more" href="{{ route('category', ['cat'=>'arenda']) }}">Показать все объекты</a> | |
166 | 166 | <div class="slider__control"> |
167 | 167 | <div class="swiper-button-prev"> |
168 | 168 | <svg width="10" height="17"> |
... | ... | @@ -196,7 +196,7 @@ |
196 | 196 | <div class="container"> |
197 | 197 | <div class="slider__wrap"> |
198 | 198 | <div class="slider__top"> |
199 | - <h2 class="slider__title title">Продажа торговых помещений</h2><a class="slider__more" href="#">Показать все объекты</a> | |
199 | + <h2 class="slider__title title">Продажа торговых помещений</h2><a class="slider__more" href="{{ route('category', ['cat'=>'sale']) }}">Показать все объекты</a> | |
200 | 200 | <div class="slider__control"> |
201 | 201 | <div class="swiper-button-prev"> |
202 | 202 | <svg width="10" height="17"> |
... | ... | @@ -229,7 +229,7 @@ |
229 | 229 | <div class="container"> |
230 | 230 | <div class="slider__wrap"> |
231 | 231 | <div class="slider__top"> |
232 | - <h2 class="slider__title title">Арендный бизнес</h2><a class="slider__more" href="#">Показать все объекты</a> | |
232 | + <h2 class="slider__title title">Арендный бизнес</h2><a class="slider__more" href="{{ route('category', ['cat'=>'bussiness']) }}">Показать все объекты</a> | |
233 | 233 | <div class="slider__control"> |
234 | 234 | <div class="swiper-button-prev"> |
235 | 235 | <svg width="10" height="17"> |
... | ... | @@ -262,7 +262,7 @@ |
262 | 262 | <div class="container"> |
263 | 263 | <div class="slider__wrap"> |
264 | 264 | <div class="slider__top"> |
265 | - <h2 class="slider__title title">Арендованные</h2><a class="slider__more" href="#">Показать все объекты</a> | |
265 | + <h2 class="slider__title title">Арендованные</h2><a class="slider__more" href="{{ route('category', ['cat'=>'arendovannie']) }}">Показать все объекты</a> | |
266 | 266 | <div class="slider__control"> |
267 | 267 | <div class="swiper-button-prev"> |
268 | 268 | <svg width="10" height="17"> |
resources/views/js/cookies_favorite.blade.php
... | ... | @@ -41,11 +41,14 @@ |
41 | 41 | // удаление элемента из массива в cookie |
42 | 42 | function delete_in_array(obj) { |
43 | 43 | var arr = read_array(); |
44 | - var index = arr.indexOf(obj); | |
45 | - arr.splice(index, 1); | |
44 | + var unique = [...new Set(arr)] | |
45 | + var index = unique.indexOf(obj); | |
46 | + | |
47 | + unique.splice(index, 1); | |
48 | + | |
46 | 49 | //var str = JSON.stringify(arr);//конвертируем в строку |
47 | 50 | //$.cookie('arr',str);//записываем массив в куки |
48 | - $.cookie('favorite_house', JSON.stringify(arr)); | |
51 | + $.cookie('favorite_house', JSON.stringify(unique)); | |
49 | 52 | } |
50 | 53 | |
51 | 54 | function read_array(){ |
resources/views/part/filter/category.blade.php
... | ... | @@ -69,10 +69,10 @@ |
69 | 69 | <div class="hero-filter__dropdown js_hero_filter_dropdown"> |
70 | 70 | <div class="hero-filter__fields"> |
71 | 71 | <label class="hero-filter__field"><span>От</span> |
72 | - <input class="js_hero_filter_field js_hero_filter_from" id="area_m2_min" name="area_m2_min" type="text" data-min="3" placeholder="3" value="<?if (isset($_GET['area_m2_min'])) { echo($_GET['area_m2_min']); }?>"> | |
72 | + <input class="js_hero_filter_field js_hero_filter_from" id="area_m2_min" name="area_m2_min" type="text" placeholder="3" value="<?if (isset($_GET['area_m2_min'])) { echo($_GET['area_m2_min']); }?>"> | |
73 | 73 | </label> |
74 | 74 | <label class="hero-filter__field"><span>До</span> |
75 | - <input class="js_hero_filter_field js_hero_filter_to" id="area_m2_max" name="area_m2_max" type="text" data-max="125000" placeholder="125 000" value="<?if (isset($_GET['area_m2_max'])) { echo($_GET['area_m2_max']);}?>"> | |
75 | + <input class="js_hero_filter_field js_hero_filter_to" id="area_m2_max" name="area_m2_max" type="text" placeholder="125 000" value="<?if (isset($_GET['area_m2_max'])) { echo($_GET['area_m2_max']);}?>"> | |
76 | 76 | </label> |
77 | 77 | </div> |
78 | 78 | <button class="hero-filter__reset js_hero_filter_reset" type="button">Очистить</button> |
... | ... | @@ -83,10 +83,10 @@ |
83 | 83 | <div class="hero-filter__dropdown js_hero_filter_dropdown"> |
84 | 84 | <div class="hero-filter__fields"> |
85 | 85 | <label class="hero-filter__field"><span>От</span> |
86 | - <input class="js_hero_filter_field js_hero_filter_from" id="price_min" name="price_min" type="text" data-min="50" placeholder="50" value="<?if (isset($_GET['price_min'])) { echo ($_GET['price_min']); } ?>"> | |
86 | + <input class="js_hero_filter_field js_hero_filter_from" id="price_min" name="price_min" type="text" placeholder="50" value="<?if (isset($_GET['price_min'])) { echo ($_GET['price_min']); } ?>"> | |
87 | 87 | </label> |
88 | 88 | <label class="hero-filter__field"><span>До</span> |
89 | - <input class="js_hero_filter_field js_hero_filter_to" id="price_max" name="price_max" type="text" data-max="125000" placeholder="125 000" value="<?if (isset($_GET['price_max'])) { echo ($_GET['price_max']); }?>"> | |
89 | + <input class="js_hero_filter_field js_hero_filter_to" id="price_max" name="price_max" type="text" placeholder="125000" value="<?if (isset($_GET['price_max'])) { echo ($_GET['price_max']); }?>"> | |
90 | 90 | </label> |
91 | 91 | </div> |
92 | 92 | <button class="hero-filter__reset js_hero_filter_reset" type="button">Очистить</button> |