app/Http/Controllers/Student/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()
    {
        $myuser = Auth::user();
        $packages = Grade::find($myuser->grade_id)->packages()->get()->toArray();
        $package_ides = array_column($packages, 'id');
        $packages = Package::where(function($package) use ($myuser, $package_ides) {
            return $package -> whereIn('id', $package_ides)
             -> orwhere('user_id', $myuser->id);
            if($myuser->country()->first()['name'] == 'Canada') {
                if($myuser->state()->first()['name'] == 'Alberta' || $myuser->state()->first()['code'] == 'AB' )
                {
                    return $package -> where('package_alb', '!=', '0.00');
                } else return $package -> where('package_can', '!=', '0.00');
            } else return $package -> where('package_usa', '!=', '0.00');
        }) -> get();
        $prices = Array();
        foreach ($packages as $package)
        {
            if($myuser->country()->first()['name'] == 'Canada') {
                if($myuser->state()->first()['name'] == 'Alberta' || $myuser->state()->first()['code'] == 'AB' )
                {
                    $prices[$package->id] = $package ->price_alb;
                } else $prices[$package->id] = $package ->price_can;
            } else $prices[$package->id] = $package ->price_usa;
        }
        return view('students.packages.index')->with('data', [
            'packages'  => $packages,
            'prices'    => $prices
        ]);
    }
public function index ( ) { $ myuser = Auth :: user ( ) ; $ packages = Grade :: find ( $ myuser -> grade_id ) -> packages ( ) -> get ( ) -> toArray ( ) ; $ package_ides = array_column ( $ packages , 'id' ) ; $ packages = Package :: where ( function ( $ package ) use ( $ myuser , $ package_ides ) { return $ package -> whereIn ( 'id' , $ package_ides ) -> orwhere ( 'user_id' , $ myuser -> id ) ; if ( $ myuser -> country ( ) -> first ( ) [ 'name' ] == 'Canada' ) { if ( $ myuser -> state ( ) -> first ( ) [ 'name' ] == 'Alberta' || $ myuser -> state ( ) -> first ( ) [ 'code' ] == 'AB' ) { return $ package -> where ( 'package_alb' , '!=' , '0.00' ) ; } else return $ package -> where ( 'package_can' , '!=' , '0.00' ) ; } else return $ package -> where ( 'package_usa' , '!=' , '0.00' ) ; } ) -> get ( ) ; $ prices = Array ( ) ; foreach ( $ packages as $ package ) { if ( $ myuser -> country ( ) -> first ( ) [ 'name' ] == 'Canada' ) { if ( $ myuser -> state ( ) -> first ( ) [ 'name' ] == 'Alberta' || $ myuser -> state ( ) -> first ( ) [ 'code' ] == 'AB' ) { $ prices [ $ package -> id ] = $ package -> price_alb ; } else $ prices [ $ package -> id ] = $ package -> price_can ; } else $ prices [ $ package -> id ] = $ package -> price_usa ; } return view ( 'students.packages.index' ) -> with ( 'data' , [ 'packages' => $ packages , 'prices' => $ prices ] ) ; }
Display a listing of the resource.
Display a listing of the resource .