/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //display all courses
     if (\Auth::check()) {
         if (\Auth::user()->role_id == 4) {
             $is_student = true;
         } else {
             $is_student = false;
         }
     } else {
         $is_student = false;
     }
     $categories = CourseCategory::all();
     $courses = DB::table('courses')->join('institutions', 'institutions.id', '=', 'courses.inst_id')->select('courses.*', 'institutions.inst_name')->where('courses.is_open', '=', true)->get();
     return view('course.view', compact('is_student', 'categories', 'courses'));
 }
 public function show($id)
 {
     if (\Auth::check()) {
         if (\Auth::user()->role_id == 2) {
             $is_mainadmin = false;
             $inst_id = Institution::where('admin_id', '=', \Auth::user()->id)->first()->id;
             $professors_verified = DB::table('professors')->join('users', 'users.id', '=', 'professors.user_id')->join('institutions', 'institutions.id', '=', 'professors.inst_id')->where('is_verified', true)->where('role_id', 3)->where('professors.inst_id', '=', $inst_id)->get();
             $professors_pending = DB::table('professors')->join('users', 'users.id', '=', 'professors.user_id')->join('institutions', 'institutions.id', '=', 'professors.inst_id')->where('is_verified', false)->where('role_id', 3)->where('professors.inst_id', '=', $inst_id)->get();
             $num_verified = collect($professors_verified)->count();
             $num_pending = collect($professors_pending)->count();
             switch ($id) {
                 case 'professors-verified':
                     $is_verified = true;
                     return view('inst_admin.professor_inst', compact('is_mainadmin', 'is_verified', 'num_pending', 'num_verified', 'professors_verified'));
                     break;
                 case 'professors-pending':
                     $is_verified = false;
                     return view('inst_admin.professor_inst', compact('is_mainadmin', 'is_verified', 'num_pending', 'num_verified', 'professors_pending'));
                     break;
                 case 'courses':
                     $inst_id = Institution::where('admin_id', \Auth::user()->id)->first()->id;
                     $is_professor = false;
                     $courses = DB::table('courses')->where('inst_id', $inst_id)->get();
                     return view('shared.courses', compact('is_mainadmin', 'is_verified', 'num_pending', 'num_verified', 'professors_pending', 'courses', 'is_professor'));
                     break;
                 case 'add_course':
                     $categories = CourseCategory::all();
                     return view('inst_admin.add_course', compact('is_mainadmin', 'num_pending', 'num_verified', 'professors_verified', 'categories'));
                 case 'category_requests':
                     return view('inst_admin.category_requests', compact('is_mainadmin', 'is_verified', 'num_pending', 'num_verified', 'professors_pending'));
                 case 'settings':
                     $email = \Auth::user()->email;
                     $is_professor = false;
                     return view('shared.settings', compact('is_mainadmin', 'email', 'num_verified', 'num_pending', 'is_professor'));
                     break;
                 case 'edit':
                     $institution = DB::table('users')->join('institutions', 'users.id', '=', 'institutions.admin_id')->where('users.id', '=', \Auth::user()->id)->first();
                     return view('inst_admin.edit_profile', compact('is_mainadmin', 'email', 'num_verified', 'num_pending', 'institution'));
                     break;
                 default:
                     return abort(404);
             }
         } else {
             return redirect('/');
         }
     }
 }