/** * 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 add_course(Request $request) { $validator = $this->course_validator($request->all()); if ($validator->fails()) { $this->throwValidationException($request, $validator); } $inst_id = Institution::where('admin_id', \Auth::user()->id)->first()->id; $categ_id = CourseCategory::where('categ_name', $request->category)->first()->id; $course = Course::create(['course_name' => $request->name, 'course_description' => $request->description, 'course_image' => $request->image, 'prof_id' => $request->professor, 'category_id' => $categ_id, 'inst_id' => $inst_id]); $imageName = "course_" . $course->id . '.' . Input::file('image')->getClientOriginalExtension(); Input::file('image')->move(base_path() . '/public/images/course/', $imageName); $course->course_image = $imageName; $course->save(); return redirect('institution/courses')->with('status', 'You have successfully added a course!'); }
public function decline_categ(Request $request) { $categ = CourseCategory::where('id', $request->input('categ_id'))->first(); $categ->delete(); return redirect('main-admin/course-categories-pending')->with('status', $categ->name . ' Course Category Declined!'); }