<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Session; 
use Hash;
use Carbon\Carbon;

class SearchController extends Controller
{
    public function search_filter(Request $request){
        
        $airport = $request->input('airport');
        $startdate = $request->input('startdate');
        $starttime = $request->input('starttime');
        $enddate = $request->input('enddate');
        $endtime = $request->input('endtime');

        //echo $airport;
        //echo $startdate;

        if($airport != '' && $startdate != '' && $enddate != '')
        {
            $details = DB::table('peak_days')
                         ->join('city_master', 'city_master.city_id', '=', 'peak_days.city_id')
                         ->join('parking_provider', 'parking_provider.providerid', '=', 'peak_days.provider_id')
                         ->where('city_name','=', $airport)->where('from','=', $startdate)->where('to','=', $enddate)->orderBy('parking_provider.providerid', 'DESC')->get();

             return view('frontend.search-result',["details" => $details]);

        } 
        // else if($airport != '' && $startdate != '') {

        //    $details = DB::table('peak_days')
        //                  ->join('city_master', 'city_master.city_id', '=', 'peak_days.city_id')
        //                  ->join('parking_provider', 'parking_provider.providerid', '=', 'peak_days.provider_id')
        //                  ->where('city_name','=',$airport)->where('from','>=',$startdate)->orderBy('parking_provider.providerid', 'DESC')->get();
        //      return view('frontend.search-result',["details" => $details]);

        // } 
        // else($airport != '' && $enddate != '') {

        //    $details = DB::table('peak_days')
        //                  ->join('city_master', 'city_master.city_id', '=', 'peak_days.city_id')
        //                  ->join('parking_provider', 'parking_provider.providerid', '=', 'peak_days.provider_id')
        //                  ->where('city_name','=',$airport)->where('to','<=',$enddate)->orderBy('parking_provider.providerid', 'DESC')->get();
        //      return view('frontend.search-result',["details" => $details]);

        // }
        else if($airport != '') {

           $details = DB::table('peak_days')
                         ->join('city_master', 'city_master.city_id', '=', 'peak_days.city_id')
                         ->join('parking_provider', 'parking_provider.providerid', '=', 'peak_days.provider_id')
                         ->where('city_name','=', $airport)->orderBy('parking_provider.providerid','DESC')->get();

             return view('frontend.search-result',["details" => $details]);

        }
        else{

           $details = DB::table('peak_days')
                         ->join('city_master', 'city_master.city_id', '=', 'peak_days.city_id')
                         ->join('parking_provider', 'parking_provider.providerid', '=', 'peak_days.provider_id')->orderBy('parking_provider.providerid','DESC')->get();

             return view('frontend.search-result',["details" => $details]);

        }

    }
}
