MainController.php 8.05 KB
<?php

namespace App\Http\Controllers;

use App\Models\Area;
use App\Models\House;
use App\Models\News;
use App\Models\Partners;
use Illuminate\Http\Request;
use App\Classes\RusDate;
use PhpParser\Node\Stmt\Switch_;

class MainController extends Controller
{
    /*
     * Главная страница проекта
     */
    public function index() {
       $houses = House::with('areas')->orderByDesc('created_at')->limit(8)->get();
       $news = News::query()->orderByDesc('created_at')->limit(8)->get();
       $partners = Partners::query()->limit(18)->get();
       return view('index', compact('houses', 'news', 'partners'));
    }

    /*
     * Страница ЖК
     */
    public function Complex(Area $area, Request $request) {
        //////////раздел аренда
        $house_arenda = House::with('areas')->
                               where('area_id', '=', $area->id)->
                               where('format_house', '=', 'Аренда');

        if ($request->view == 'arenda') {
            switch ($request->sort_price) {
                case 1: $house_arenda = $house_arenda->orderBy('rent_in_month');break;
                case 2: $house_arenda = $house_arenda->orderByDesc('rent_in_month');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;
            }
        } else {
            $house_arenda = $house_arenda->orderBy('rent_in_year')->
                                           orderByDesc('created_at')->
                                           orderByDesc('area')->get();
        }

        ////////раздел продажа
        $house_prodaja = House::with('areas')->
                                //where('area_id', '=', $area->id)->
                                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;
            }
        } else {
            $house_prodaja = $house_prodaja->orderBy('price')->
                                            orderByDesc('created_at')->
                                            orderByDesc('area')->get();
        }

        //////////////// Раздел бизнеса
        $house_bissnes = House::with('areas')->
                                where('area_id', '=', $area->id)->
                                where('format_house', '=', 'Бизнес');
                                //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;
            }
        } else {
            $house_bissnes = $house_bissnes->orderBy('price')->
                                             orderByDesc('created_at')->
                                             orderByDesc('area')->get();
        }

        //////////раздел арендованные
        $house_arendovannie = House::with('areas')->
                                     where('area_id', '=', $area->id)->
                                     where('format_house', '=', 'Арендованные');
                                     //orderByDesc('created_at')->get();

        if ($request->view == 'arendovannie') {
            switch ($request->sort_price) {
                case 1: $house_arendovannie = $house_arendovannie->orderBy('rent_in_month');break;
                case 2: $house_arendovannie = $house_arendovannie->orderByDesc('rent_in_month');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;
            }
        } else {
            $house_arendovannie = $house_arendovannie->orderBy('rent_in_year')->
            orderByDesc('created_at')->
            orderByDesc('area')->get();
        }

        if ($request->ajax()) {
            switch($request->view) {
                case 'arenda': return view('ajax.complex.arenda', compact('house_arenda')); break;
                case 'prodaja': return view('ajax.complex.prodaja', compact('house_prodaja'));break;
                case 'bissnes': return view('ajax.complex.bissnes', compact('house_bissnes')); break;
                case 'arendovannie': return view('ajax.complex.arendovannie', compact('house_arendovannie')); break;
            }
        }

        return view('complex', compact('area',
                                           'house_arenda',
                                                     'house_prodaja',
                                                     'house_bissnes',
                                                     'house_arendovannie'));

    }

    /*
     * О компании
     */
    public function About() {
        return view('about');
    }

    /*
     * Избранное
     */
    public function Favorite() {
        return view('favorite');
    }

    /*
     * Каталог
     */
    public function Catalog() {
        return view('catalog');
    }

    /*
     * Новости
     */
    public function News() {
        //$news = News::orderByDesc('created_at')->limit(1)->paginate();
        $news_ = News::query()->orderByDesc('created_at')->paginate(4);
        return view('news', compact('news_'));
    }

    /*
     * Контакты
     */
    public function Contact() {
        return view('contact');
    }

    /*
     * Карта объектов
     */
    public function MapsObj() {
        return view('mapsobj');
    }

    /*
     * Посмотр конктретного предложение офиса
     */
    public function Offer(House $house) {
        $houses = House::with('areas');
        $houses =  $houses->where('type_area_id', '=', $house->typearea->id);
        $houses = $houses->where('format_house', '=', $house->format_house);
        $houses = $houses->orderByDesc('created_at')->limit(8)->get();

        return view('house.post', compact('house', 'houses'));
    }

    /*
     * Просмотр детально конкретной новости
     */
    public function DetailNew(News $news) {
        $news_list = News::query()->orderByDesc('created_at')->limit(8)->get();
        return view('new.post', compact('news', 'news_list'));
    }
}