diff --git a/app/Classes/FilterData.php b/app/Classes/FilterData.php new file mode 100644 index 0000000..092f86b --- /dev/null +++ b/app/Classes/FilterData.php @@ -0,0 +1,61 @@ +builder = $builder; + $this->request = $request; + } + + public function apply() { + foreach ($this->filters() as $filter => $value) { + if (method_exists($this, $filter)) { + $this->filter($value); + } + } + return $this->builder; + } + + public function area($value) { + return $this->builder->where('area_id', '=', $value); + } + + public function type_area($value) { + return $this->builder->where('type_area_id', '=', $value); + } + + public function format_area($value) { + return $this->builder->where('format_area_id', '=', $value); + } + + public function area_m2_min($value) { + return $this->builder->where('area', '>', $value); + } + + public function area_m2_max($value) { + return $this->builder->where('area', '<', $value); + } + + public function price_min($value) { + return $this->builder->where('price', '>', $value); + } + + public function price_max($value) { + return $this->builder->where('price', '<', $value); + } + + public function address($value) { + return $this->builder->where('address', 'LIKE', "%".$value."%"); + } + + public function filters() { + return $this->request->all(); + } +} diff --git a/app/Classes/SortData.php b/app/Classes/SortData.php new file mode 100644 index 0000000..7ad701f --- /dev/null +++ b/app/Classes/SortData.php @@ -0,0 +1,54 @@ +builder = $builder; + $this->request = $request; + } + + public function apply() { + foreach ($this->sorter() as $filter => $value) { + if (method_exists($this, $filter)) { + $this->filter($value); + } + } + return $this->builder; + } + + public function sort_price($value) { + switch ($value) { + case 1: $this->builder = $this->builder->orderBy('price');break; + case 2: $this->builder = $this->builder->orderByDesc('price');break; + default: $this->builder = $this->builder->orderBy('price');break; + } + } + + public function sort_new($value) { + switch ($value) { + case 1: $this->builder = $this->builder->orderByDesc('created_at');break; + case 2: $this->builder = $this->builder->orderBy('created_at');break; + default: $this->builder = $this->builder->orderByDesc('created_at');break; + } + } + + public function sort_area($value) { + switch ($value) { + case 1: $this->builder = $this->builder->orderByDesc('area');break; + case 2: $this->builder = $this->builder->orderBy('area');break; + default: $this->builder = $this->builder->orderByDesc('area');break; + } + } + + public function sorter() { + return $this->request->all(); + } + +} diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index 089bddd..a03cf19 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -20,6 +20,7 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Mail; use PhpParser\Node\Stmt\Switch_; use Illuminate\Support\Facades\Response; +use App\Classes\FilterData; class MainController extends Controller { @@ -406,6 +407,19 @@ class MainController extends Controller return view('category_catalog', compact('title', 'cat', 'houses')); } + public function Test(Request $request) { + $house_arenda = House::with('areas')-> + where('format_house', '=', 'Аренда'); + + $house_arenda = $house_arenda->orderByDesc('price')-> + orderByDesc('created_at')-> + orderByDesc('area')->get(); + + + return view('ajax.complex.arenda', compact('house_arenda')); + + } + /* * Каталог @@ -416,6 +430,10 @@ class MainController extends Controller $house_arenda = House::with('areas')-> where('format_house', '=', 'Аренда'); // условия поиска по объектам комплексов + + //$house_arenda = (new FilterData($house_arenda, $request))->apply(); + + if (!empty($request->area)) { $house_arenda = $house_arenda->where('area_id', '=', $request->area); } @@ -448,6 +466,7 @@ class MainController extends Controller $house_arenda = $house_arenda->where('address', 'LIKE', "%".$request->address."%"); } + if ($request->view == 'arenda') { switch ($request->sort_price) { case 1: $house_arenda = $house_arenda->orderBy('price');break; diff --git a/app/Providers/ComposerServiceProvider.php b/app/Providers/ComposerServiceProvider.php index 49f7bfc..6951507 100644 --- a/app/Providers/ComposerServiceProvider.php +++ b/app/Providers/ComposerServiceProvider.php @@ -34,7 +34,8 @@ class ComposerServiceProvider extends ServiceProvider } ); - $views = ['layout.site', 'index', 'about', 'house.post', 'catalog', 'category_catalog']; + $views = ['layout.site', 'index', 'about', 'house.post', 'catalog', 'category_catalog', + 'catalogs.elemhouse', 'catalogs.house_mini']; View::composer($views, function($view) { $view->with(['items_contact' => Contact::limit(1)->get()]); }); diff --git a/resources/views/catalog.blade.php b/resources/views/catalog.blade.php index b3bbe65..24d76a8 100644 --- a/resources/views/catalog.blade.php +++ b/resources/views/catalog.blade.php @@ -35,7 +35,7 @@ }); - console.log('-------------------'); + console.log('-----Загрузка ajax аренда---------'); $.ajax({ type: "GET", url: "{{ route('catalog') }}", @@ -55,6 +55,7 @@ } }); + console.log('---ajax продажи---'); $.ajax({ type: "GET", url: "{{ route('catalog') }}", @@ -74,6 +75,7 @@ } }); + console.log('---ajax бизнес---'); $.ajax({ type: "GET", url: "{{ route('catalog') }}", @@ -93,6 +95,7 @@ } }); + console.log('---ajax арендованные---'); $.ajax({ type: "GET", url: "{{ route('catalog') }}", @@ -101,7 +104,7 @@ "&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'];?>"+ "&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'];?>", success: function(data) { - console.log('Успешно обновлены данные таблиц '); + console.log('Успешно обновлены данные таблиц АРЕНДОВАННЫЕ '); $('#arendovannie_block').html(data); //.append(data); }, diff --git a/resources/views/catalogs/elemhouse.blade.php b/resources/views/catalogs/elemhouse.blade.php index 7c914cc..25d8100 100644 --- a/resources/views/catalogs/elemhouse.blade.php +++ b/resources/views/catalogs/elemhouse.blade.php @@ -17,7 +17,7 @@ - + diff --git a/resources/views/layout/site.blade.php b/resources/views/layout/site.blade.php index 63217d1..fbbd15b 100644 --- a/resources/views/layout/site.blade.php +++ b/resources/views/layout/site.blade.php @@ -4,6 +4,7 @@ +