app/Http/Controllers/PackagesController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index(Request $request)
    {
        $title = 'Adventures';
        $avd = Schedule::query();
        $packagesq = DB::table('packages')
                        ->leftJoin('prices', 'packages.id', '=', 'prices.package_id')
                        ->selectRaw('* , packages.id as pid')
                        ->where('prices.is_display','=',1)
                        ->whereNull('packages.deleted_at');
        if(!is_null($request->query('difficulty'))) {
            if($request->query('difficulty') == 'all') {
                $packagesq = DB::table('packages')
                                ->leftJoin('prices', 'packages.id', '=', 'prices.package_id')
                                ->selectRaw('* , packages.id as pid')
                                ->where('prices.is_display','=',1)
                                ->whereNull('packages.deleted_at');
            } else {
                $packagesq = DB::table('packages')
                                ->leftJoin('prices', 'packages.id', '=', 'prices.package_id')
                                ->selectRaw('* , packages.id as pid')
                                ->where('prices.is_display','=',1)
                                ->whereNull('packages.deleted_at')
                                ->where('difficulty','=',$request->query('difficulty'));
            }
        }
        if(!is_null($request->query('type'))) {
            if($request->query('type') == 'all') {
                $packagesq = $packagesq;
            } else {
                $packagesq = DB::table('packages')
                                ->leftJoin('prices', 'packages.id', '=', 'prices.package_id')
                                ->selectRaw('* , packages.id as pid')
                                ->where('prices.is_display','=',1)
                                ->whereNull('packages.deleted_at')
                                ->where('adventure_type','like','%'.$request->query('type').'%');
            }
        }
        if(!is_null($request->query('date'))) {
            $packagesq = Package::selectRaw('* , packages.id as pid');
            $dateselect = $request->query('date');
            $flag = 1;
            $dateselect = date("Y-m-d", strtotime($dateselect));
            if($request->query('date') == 'all') {
                $packagesq = $packagesq;
            } else {
                $packagesq = $packagesq->whereHas('schedules', function ($q) use($dateselect){
                    $q->where('date', $dateselect);
                })->whereHas('prices',function($q) use($flag){
                    $q->where('is_display',$flag);
                })->leftJoin('prices', 'packages.id', '=', 'prices.package_id')->where('prices.is_display','=',1);
            }
        }
        $packages = $packagesq->paginate(20);
        $data = array(
            'packages'   => $packages,
            'title'     => $title
        ); 
        if ($request->ajax()) {          
            return Response::json(view('Packages.renderpackages')->with('packages',$data['packages'])->render() );
        } else {
            return view('Packages.packages')->with('pagedata',$data);
        }
    }
public function index ( Request $ request ) { $ title = 'Adventures' ; $ avd = Schedule :: query ( ) ; $ packagesq = DB :: table ( 'packages' ) -> leftJoin ( 'prices' , 'packages.id' , '=' , 'prices.package_id' ) -> selectRaw ( '* , packages.id as pid' ) -> where ( 'prices.is_display' , '=' , 1 ) -> whereNull ( 'packages.deleted_at' ) ; if ( ! is_null ( $ request -> query ( 'difficulty' ) ) ) { if ( $ request -> query ( 'difficulty' ) == 'all' ) { $ packagesq = DB :: table ( 'packages' ) -> leftJoin ( 'prices' , 'packages.id' , '=' , 'prices.package_id' ) -> selectRaw ( '* , packages.id as pid' ) -> where ( 'prices.is_display' , '=' , 1 ) -> whereNull ( 'packages.deleted_at' ) ; } else { $ packagesq = DB :: table ( 'packages' ) -> leftJoin ( 'prices' , 'packages.id' , '=' , 'prices.package_id' ) -> selectRaw ( '* , packages.id as pid' ) -> where ( 'prices.is_display' , '=' , 1 ) -> whereNull ( 'packages.deleted_at' ) -> where ( 'difficulty' , '=' , $ request -> query ( 'difficulty' ) ) ; } } if ( ! is_null ( $ request -> query ( 'type' ) ) ) { if ( $ request -> query ( 'type' ) == 'all' ) { $ packagesq = $ packagesq ; } else { $ packagesq = DB :: table ( 'packages' ) -> leftJoin ( 'prices' , 'packages.id' , '=' , 'prices.package_id' ) -> selectRaw ( '* , packages.id as pid' ) -> where ( 'prices.is_display' , '=' , 1 ) -> whereNull ( 'packages.deleted_at' ) -> where ( 'adventure_type' , 'like' , '%' . $ request -> query ( 'type' ) . '%' ) ; } } if ( ! is_null ( $ request -> query ( 'date' ) ) ) { $ packagesq = Package :: selectRaw ( '* , packages.id as pid' ) ; $ dateselect = $ request -> query ( 'date' ) ; $ flag = 1 ; $ dateselect = date ( " Y-m-d " , strtotime ( $ dateselect ) ) ; if ( $ request -> query ( 'date' ) == 'all' ) { $ packagesq = $ packagesq ; } else { $ packagesq = $ packagesq -> whereHas ( 'schedules' , function ( $ q ) use ( $ dateselect ) { $ q -> where ( 'date' , $ dateselect ) ; } ) -> whereHas ( 'prices' , function ( $ q ) use ( $ flag ) { $ q -> where ( 'is_display' , $ flag ) ; } ) -> leftJoin ( 'prices' , 'packages.id' , '=' , 'prices.package_id' ) -> where ( 'prices.is_display' , '=' , 1 ) ; } } $ packages = $ packagesq -> paginate ( 20 ) ; $ data = array ( 'packages' => $ packages , 'title' => $ title ) ; if ( $ request -> ajax ( ) ) { return Response :: json ( view ( 'Packages.renderpackages' ) -> with ( 'packages' , $ data [ 'packages' ] ) -> render ( ) ) ; } else { return view ( 'Packages.packages' ) -> with ( 'pagedata' , $ data ) ; } }
Display a listing of the resource.
Display a listing of the resource .