MainController.php 3.6 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;

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) {
        $house_arenda = House::with('areas')->
                               where('area_id', '=', $area->id)->
                               where('format_house', '=', 'Аренда')->
                               orderByDesc('created_at')->get();

        $house_prodaja = House::with('areas')->
                                where('area_id', '=', $area->id)->
                                where('format_house', '=', 'Продажа')->
                                orderByDesc('created_at')->get();

        $house_bissnes = House::with('areas')->
                                where('area_id', '=', $area->id)->
                                where('format_house', '=', 'Бизнес')->
                                orderByDesc('created_at')->get();

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

        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'));
    }
}