<?php

namespace App\Http\Controllers\Frontend;

use App\Models\Blog;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class HomeController extends Controller {
	//
	public function index( Request $request ) {
		if (str_contains($request->getHost(), 'quanlynhatro.com')) {


			$blog = Blog::query()
			            ->where( 'is_sale', true )
			            ->where( function ( $q ) {
				            $q->orWhere( function ( $q ) {
					            $q->whereNull( 'start_date' );
					            $q->where( 'end_date', '>=', Carbon::now()->toDateString() );
				            } );
				            $q->orWhere( function ( $q ) {
					            $q->whereNull( 'end_date' );
					            $q->where( 'start_date', '<=', Carbon::now()->toDateString() );
				            } );

				            $q->orWhere( function ( $q ) {
					            $q->where( 'start_date', '<=', Carbon::now()->toDateString() )
					              ->where( 'end_date', '>=', Carbon::now()->toDateString() );
				            } );
			            } )
			            ->orderBy( 'id', 'desc' )
			            ->first();

			return view( 'frontend3.introduction2', compact( 'blog' ) );

		}

		return view( 'landing_home' );
	}
}
