diff --git a/app/Classes/FilterData.php b/app/Classes/FilterData.php index 092f86b..3694b25 100644 --- a/app/Classes/FilterData.php +++ b/app/Classes/FilterData.php @@ -17,7 +17,7 @@ class FilterData public function apply() { foreach ($this->filters() as $filter => $value) { if (method_exists($this, $filter)) { - $this->filter($value); + if (!empty($value)) $this->$filter($value); } } return $this->builder; @@ -36,23 +36,32 @@ class FilterData } public function area_m2_min($value) { - return $this->builder->where('area', '>', $value); + $value = str_replace("+", "", $value); + $value = str_replace(' ', '', $value); + if ($value) return $this->builder->where('area', '>', $value); } public function area_m2_max($value) { - return $this->builder->where('area', '<', $value); + $value = str_replace("+", "", $value); + $value = str_replace(' ', '', $value); + if ($value) return $this->builder->where('area', '<', $value); } public function price_min($value) { - return $this->builder->where('price', '>', $value); + $value = str_replace("+", "", $value); + $value = str_replace(' ', '', $value); + + if ($value) return $this->builder->where('price', '>', $value); } public function price_max($value) { - return $this->builder->where('price', '<', $value); + $value = str_replace("+", "", $value); + $value = str_replace(' ', '', $value); + if ($value) return $this->builder->where('price', '<', $value); } public function address($value) { - return $this->builder->where('address', 'LIKE', "%".$value."%"); + if ($value) return $this->builder->where('address', 'LIKE', "%".$value."%"); } public function filters() { diff --git a/app/Classes/SortData.php b/app/Classes/SortData.php index 7ad701f..9a3f366 100644 --- a/app/Classes/SortData.php +++ b/app/Classes/SortData.php @@ -17,7 +17,7 @@ class SortData public function apply() { foreach ($this->sorter() as $filter => $value) { if (method_exists($this, $filter)) { - $this->filter($value); + $this->$filter($value); } } return $this->builder; diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index a03cf19..f29439e 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Classes\SortData; use App\Http\Requests\EmailRequest; use App\Http\Requests\FooterFeedbackRequest; use App\Models\Area; @@ -73,18 +74,8 @@ class MainController extends Controller where('format_house', '=', 'Аренда'); if ($request->view == 'arenda') { - switch ($request->sort_price) { - case 1: $house_arenda = $house_arenda->orderBy('price');break; - case 2: $house_arenda = $house_arenda->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $house_arenda = $house_arenda->orderByDesc('created_at');break; - case 2: $house_arenda = $house_arenda->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $house_arenda = $house_arenda->orderByDesc('area')->get();break; - case 2: $house_arenda = $house_arenda->orderBy('area')->get();break; - } + $house_arenda = (new SortData($house_arenda, $request))->apply()->get(); + } else { $house_arenda = $house_arenda->orderBy('price')-> orderByDesc('created_at')-> @@ -97,18 +88,8 @@ class MainController extends Controller where('format_house', '=', 'Продажа'); if ($request->view == 'prodaja') { - switch ($request->sort_price) { - case 1: $house_prodaja = $house_prodaja->orderBy('price');break; - case 2: $house_prodaja = $house_prodaja->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $house_prodaja = $house_prodaja->orderByDesc('created_at');break; - case 2: $house_prodaja = $house_prodaja->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $house_prodaja = $house_prodaja->orderByDesc('area')->get();break; - case 2: $house_prodaja = $house_prodaja->orderBy('area')->get();break; - } + $house_prodaja = (new SortData($house_prodaja, $request))->apply()->get(); + } else { $house_prodaja = $house_prodaja->orderBy('price')-> orderByDesc('created_at')-> @@ -122,18 +103,8 @@ class MainController extends Controller //orderByDesc('created_at')->get(); if ($request->view == 'bissnes') { - switch ($request->sort_price) { - case 1: $house_bissnes = $house_bissnes->orderBy('price');break; - case 2: $house_bissnes = $house_bissnes->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $house_bissnes = $house_bissnes->orderByDesc('created_at');break; - case 2: $house_bissnes = $house_bissnes->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $house_bissnes = $house_bissnes->orderByDesc('area')->get();break; - case 2: $house_bissnes = $house_bissnes->orderBy('area')->get();break; - } + $house_bissnes = (new SortData($house_bissnes, $request))->apply()->get(); + } else { $house_bissnes = $house_bissnes->orderBy('price')-> orderByDesc('created_at')-> @@ -147,18 +118,8 @@ class MainController extends Controller //orderByDesc('created_at')->get(); if ($request->view == 'arendovannie') { - switch ($request->sort_price) { - case 1: $house_arendovannie = $house_arendovannie->orderBy('price');break; - case 2: $house_arendovannie = $house_arendovannie->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $house_arendovannie = $house_arendovannie->orderByDesc('created_at');break; - case 2: $house_arendovannie = $house_arendovannie->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $house_arendovannie = $house_arendovannie->orderByDesc('area')->get();break; - case 2: $house_arendovannie = $house_arendovannie->orderBy('area')->get();break; - } + $house_arendovannie = (new SortData($house_arendovannie, $request))->apply()->get(); + } else { $house_arendovannie = $house_arendovannie->orderBy('price')-> orderByDesc('created_at')-> @@ -286,18 +247,8 @@ class MainController extends Controller $houses = House::with('areas')->whereIn('id', $Arr); if (isset($request->sort_price)) { - switch ($request->sort_price) { - case 1: $houses = $houses->orderBy('price');break; - case 2: $houses = $houses->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $houses = $houses->orderByDesc('created_at');break; - case 2: $houses = $houses->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $houses = $houses->orderByDesc('area');break; - case 2: $houses = $houses->orderBy('area');break; - } + $houses = (new SortData($houses, $request))->apply(); + } else { $houses = $houses->orderBy('price')-> @@ -320,7 +271,7 @@ class MainController extends Controller } /* - * Категории каталога Аренда/Продажа/Бизнес + * Категории каталога Аренда/Продажа/Бизнес/Арендованные */ public function Category($cat, Request $request) { switch ($cat) { @@ -336,6 +287,10 @@ class MainController extends Controller $title = "Арендый бизнес"; $format_house = 'Бизнес'; break; + case 'arendovannie': + $title = "Арендованные"; + $format_house = 'Арендованные'; + break; default: $title = "Аренда торговых помещениий"; $format_house = 'Аренда'; @@ -346,51 +301,11 @@ class MainController extends Controller where('format_house', '=', $format_house); //->appends(request()->query()); - if (!empty($request->area)) { - $houses = $houses->where('area_id', '=', $request->area); - } - // условия поиска по типу недвижимости - if (!empty($request->type_area)) { - $houses = $houses->where('type_area_id', '=', $request->type_area); - } - // условия поиска по формату недвижимости - if (!empty($request->format_area)) { - $houses = $houses->where('format_area_id', '=', $request->format_area); - } - // условия поиска по площади - минимальная площадь - if (!empty($request->area_m2_min)) { - $houses = $houses->where('area', '>', $request->area_m2_min); - } - // условия поиска по площади - максимальная площадь - if (!empty($request->area_m2_max)) { - $houses = $houses->where('area', '<', $request->area_m2_max); - } - // условия поиска по цене - минимальная цена - if (!empty($request->price_min)) { - $houses = $houses->where('price', '>', $request->price_min); - } - // условия поиска по цене - максимальная цена - if (!empty($request->price_max)) { - $houses = $houses->where('price', '<', $request->price_max); - } - // условия поиска по адресу - if (!empty($request->address)) { - $houses = $houses->where('address', 'LIKE', "%".$request->address."%"); - } + $houses = (new FilterData($houses, $request))->apply(); if (isset($request->sort_price)) { - switch ($request->sort_price) { - case 1: $houses = $houses->orderBy('price');break; - case 2: $houses = $houses->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $houses = $houses->orderByDesc('created_at');break; - case 2: $houses = $houses->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $houses = $houses->orderByDesc('area');break; - case 2: $houses = $houses->orderBy('area');break; - } + $houses = (new SortData($houses, $request))->apply(); + } else { $houses = $houses->orderBy('price')-> @@ -431,55 +346,10 @@ class MainController extends Controller where('format_house', '=', 'Аренда'); // условия поиска по объектам комплексов - //$house_arenda = (new FilterData($house_arenda, $request))->apply(); - - - if (!empty($request->area)) { - $house_arenda = $house_arenda->where('area_id', '=', $request->area); - } - // условия поиска по типу недвижимости - if (!empty($request->type_area)) { - $house_arenda = $house_arenda->where('type_area_id', '=', $request->type_area); - } - // условия поиска по формату недвижимости - if (!empty($request->format_area)) { - $house_arenda = $house_arenda->where('format_area_id', '=', $request->format_area); - } - // условия поиска по площади - минимальная площадь - if (!empty($request->area_m2_min)) { - $house_arenda = $house_arenda->where('area', '>', $request->area_m2_min); - } - // условия поиска по площади - максимальная площадь - if (!empty($request->area_m2_max)) { - $house_arenda = $house_arenda->where('area', '<', $request->area_m2_max); - } - // условия поиска по цене - минимальная цена - if (!empty($request->price_min)) { - $house_arenda = $house_arenda->where('price', '>', $request->price_min); - } - // условия поиска по цене - максимальная цена - if (!empty($request->price_max)) { - $house_arenda = $house_arenda->where('price', '<', $request->price_max); - } - // условия поиска по адресу - if (!empty($request->address)) { - $house_arenda = $house_arenda->where('address', 'LIKE', "%".$request->address."%"); - } - + $house_arenda = (new FilterData($house_arenda, $request))->apply(); if ($request->view == 'arenda') { - switch ($request->sort_price) { - case 1: $house_arenda = $house_arenda->orderBy('price');break; - case 2: $house_arenda = $house_arenda->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $house_arenda = $house_arenda->orderByDesc('created_at');break; - case 2: $house_arenda = $house_arenda->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $house_arenda = $house_arenda->orderByDesc('area')->get();break; - case 2: $house_arenda = $house_arenda->orderBy('area')->get();break; - } + $house_arenda = (new SortData($house_arenda, $request))->apply()->get(); } else { $house_arenda = $house_arenda->orderBy('price')-> orderByDesc('created_at')-> @@ -490,52 +360,11 @@ class MainController extends Controller $house_prodaja = House::with('areas')-> where('format_house', '=', 'Продажа'); - // условия поиска по объектам комплексов - if (!empty($request->area)) { - $house_prodaja = $house_prodaja->where('area_id', '=', $request->area); - } - // условия поиска по типу недвижимости - if (!empty($request->type_area)) { - $house_prodaja = $house_prodaja->where('type_area_id', '=', $request->type_area); - } - // условия поиска по формату недвижимости - if (!empty($request->format_area)) { - $house_prodaja = $house_prodaja->where('format_area_id', '=', $request->format_area); - } - // условия поиска по площади - минимальная площадь - if (!empty($request->area_m2_min)) { - $house_prodaja = $house_prodaja->where('area', '>', $request->area_m2_min); - } - // условия поиска по площади - максимальная площадь - if (!empty($request->area_m2_max)) { - $house_prodaja = $house_prodaja->where('area', '<', $request->area_m2_max); - } - // условия поиска по цене - минимальная цена - if (!empty($request->price_min)) { - $house_prodaja = $house_prodaja->where('price', '>', $request->price_min); - } - // условия поиска по цене - максимальная цена - if (!empty($request->price_max)) { - $house_prodaja = $house_prodaja->where('price', '<', $request->price_max); - } - // условия поиска по адресу - if (!empty($request->address)) { - $house_prodaja = $house_prodaja->where('address', 'LIKE', "%".$request->address."%"); - } + $house_prodaja = (new FilterData($house_prodaja, $request))->apply(); if ($request->view == 'prodaja') { - switch ($request->sort_price) { - case 1: $house_prodaja = $house_prodaja->orderBy('price');break; - case 2: $house_prodaja = $house_prodaja->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $house_prodaja = $house_prodaja->orderByDesc('created_at');break; - case 2: $house_prodaja = $house_prodaja->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $house_prodaja = $house_prodaja->orderByDesc('area')->get();break; - case 2: $house_prodaja = $house_prodaja->orderBy('area')->get();break; - } + $house_prodaja = (new SortData($house_prodaja, $request))->apply()->get(); + } else { $house_prodaja = $house_prodaja->orderBy('price')-> orderByDesc('created_at')-> @@ -547,52 +376,11 @@ class MainController extends Controller where('format_house', '=', 'Бизнес'); //orderByDesc('created_at')->get(); - // условия поиска по объектам комплексов - if (!empty($request->area)) { - $house_bissnes = $house_bissnes->where('area_id', '=', $request->area); - } - // условия поиска по типу недвижимости - if (!empty($request->type_area)) { - $house_bissnes = $house_bissnes->where('type_area_id', '=', $request->type_area); - } - // условия поиска по формату недвижимости - if (!empty($request->format_area)) { - $house_bissnes = $house_bissnes->where('format_area_id', '=', $request->format_area); - } - // условия поиска по площади - минимальная площадь - if (!empty($request->area_m2_min)) { - $house_bissnes = $house_bissnes->where('area', '>', $request->area_m2_min); - } - // условия поиска по площади - максимальная площадь - if (!empty($request->area_m2_max)) { - $house_bissnes = $house_bissnes->where('area', '<', $request->area_m2_max); - } - // условия поиска по цене - минимальная цена - if (!empty($request->price_min)) { - $house_bissnes = $house_bissnes->where('price', '>', $request->price_min); - } - // условия поиска по цене - максимальная цена - if (!empty($request->price_max)) { - $house_bissnes = $house_bissnes->where('price', '<', $request->price_max); - } - // условия поиска по адресу - if (!empty($request->address)) { - $house_bissnes = $house_bissnes->where('address', 'LIKE', "%".$request->address."%"); - } + $house_bissnes = (new FilterData($house_bissnes, $request))->apply(); if ($request->view == 'bissnes') { - switch ($request->sort_price) { - case 1: $house_bissnes = $house_bissnes->orderBy('price');break; - case 2: $house_bissnes = $house_bissnes->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $house_bissnes = $house_bissnes->orderByDesc('created_at');break; - case 2: $house_bissnes = $house_bissnes->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $house_bissnes = $house_bissnes->orderByDesc('area')->get();break; - case 2: $house_bissnes = $house_bissnes->orderBy('area')->get();break; - } + $house_bissnes = (new SortData($house_bissnes, $request))->apply()->get(); + } else { $house_bissnes = $house_bissnes->orderBy('price')-> orderByDesc('created_at')-> @@ -604,52 +392,11 @@ class MainController extends Controller where('format_house', '=', 'Арендованные'); //orderByDesc('created_at')->get(); - // условия поиска по объектам комплексов - if (!empty($request->area)) { - $house_arendovannie = $house_arendovannie->where('area_id', '=', $request->area); - } - // условия поиска по типу недвижимости - if (!empty($request->type_area)) { - $house_arendovannie = $house_arendovannie->where('type_area_id', '=', $request->type_area); - } - // условия поиска по формату недвижимости - if (!empty($request->format_area)) { - $house_arendovannie = $house_arendovannie->where('format_area_id', '=', $request->format_area); - } - // условия поиска по площади - минимальная площадь - if (!empty($request->area_m2_min)) { - $house_arendovannie = $house_arendovannie->where('area', '>', $request->area_m2_min); - } - // условия поиска по площади - максимальная площадь - if (!empty($request->area_m2_max)) { - $house_arendovannie = $house_arendovannie->where('area', '<', $request->area_m2_max); - } - // условия поиска по цене - минимальная цена - if (!empty($request->price_min)) { - $house_arendovannie = $house_arendovannie->where('price', '>', $request->price_min); - } - // условия поиска по цене - максимальная цена - if (!empty($request->price_max)) { - $house_arendovannie = $house_arendovannie->where('price', '<', $request->price_max); - } - // условия поиска по адресу - if (!empty($request->address)) { - $house_arendovannie = $house_arendovannie->where('address', 'LIKE', "%".$request->address."%"); - } + $house_arendovannie = (new FilterData($house_arendovannie, $request))->apply(); if ($request->view == 'arendovannie') { - switch ($request->sort_price) { - case 1: $house_arendovannie = $house_arendovannie->orderBy('price');break; - case 2: $house_arendovannie = $house_arendovannie->orderByDesc('price');break; - } - switch ($request->sort_new) { - case 1: $house_arendovannie = $house_arendovannie->orderByDesc('created_at');break; - case 2: $house_arendovannie = $house_arendovannie->orderBy('created_at');break; - } - switch ($request->sort_area) { - case 1: $house_arendovannie = $house_arendovannie->orderByDesc('area')->get();break; - case 2: $house_arendovannie = $house_arendovannie->orderBy('area')->get();break; - } + $house_arendovannie = (new SortData($house_arendovannie, $request))->apply()->get(); + } else { $house_arendovannie = $house_arendovannie->orderBy('price')-> orderByDesc('created_at')-> @@ -712,39 +459,7 @@ class MainController extends Controller if (empty($input)) { } else { - - // условия поиска по объектам комплексов - if (!empty($request->area)) { - $houses = $houses->where('area_id', '=', $request->area); - } - // условия поиска по типу недвижимости - if (!empty($request->type_area)) { - $houses = $houses->where('type_area_id', '=', $request->type_area); - } - // условия поиска по формату недвижимости - if (!empty($request->format_area)) { - $houses = $houses->where('format_area_id', '=', $request->format_area); - } - // условия поиска по площади - минимальная площадь - if (!empty($request->area_m2_min)) { - $houses = $houses->where('area', '>', $request->area_m2_min); - } - // условия поиска по площади - максимальная площадь - if (!empty($request->area_m2_max)) { - $houses = $houses->where('area', '<', $request->area_m2_max); - } - // условия поиска по цене - минимальная цена - if (!empty($request->price_min)) { - $houses = $houses->where('price', '>', $request->price_min); - } - // условия поиска по цене - максимальная цена - if (!empty($request->price_max)) { - $houses = $houses->where('price', '<', $request->price_max); - } - // условия поиска по адресу - if (!empty($request->address)) { - $houses = $houses->where('address', 'LIKE', "%".$request->address."%"); - } + $houses = (new FilterData($houses, $request))->apply(); } $houses = $houses->orderByDesc('id')->get(); diff --git a/resources/views/catalog.blade.php b/resources/views/catalog.blade.php index 24d76a8..05fd3d9 100644 --- a/resources/views/catalog.blade.php +++ b/resources/views/catalog.blade.php @@ -162,7 +162,7 @@
-

Аренда торговых помещений

Показать все объекты +

Аренда торговых помещений

Показать все объекты
@@ -196,7 +196,7 @@
-

Продажа торговых помещений

Показать все объекты +

Продажа торговых помещений

Показать все объекты
@@ -229,7 +229,7 @@
-

Арендный бизнес

Показать все объекты +

Арендный бизнес

Показать все объекты
@@ -262,7 +262,7 @@
-

Арендованные

Показать все объекты +

Арендованные

Показать все объекты
diff --git a/resources/views/js/cookies_favorite.blade.php b/resources/views/js/cookies_favorite.blade.php index c2085c1..8ec6e16 100644 --- a/resources/views/js/cookies_favorite.blade.php +++ b/resources/views/js/cookies_favorite.blade.php @@ -41,11 +41,14 @@ // удаление элемента из массива в cookie function delete_in_array(obj) { var arr = read_array(); - var index = arr.indexOf(obj); - arr.splice(index, 1); + var unique = [...new Set(arr)] + var index = unique.indexOf(obj); + + unique.splice(index, 1); + //var str = JSON.stringify(arr);//конвертируем в строку //$.cookie('arr',str);//записываем массив в куки - $.cookie('favorite_house', JSON.stringify(arr)); + $.cookie('favorite_house', JSON.stringify(unique)); } function read_array(){ diff --git a/resources/views/part/filter/category.blade.php b/resources/views/part/filter/category.blade.php index a0e34ba..7b14edd 100644 --- a/resources/views/part/filter/category.blade.php +++ b/resources/views/part/filter/category.blade.php @@ -69,10 +69,10 @@
@@ -83,10 +83,10 @@