public function getCoursesInCategory($slug) { $articles = Article::published()->orderBy('published_at', 'desc')->take(2)->get(); $category = Category::where('slug', $slug)->first(); $courses = Course::published()->where('category_id', $category->id)->get(); return view('courses.index', ['courses' => $courses, 'page_id' => $slug, 'category' => $category, 'latest_articles' => $articles]); }
public function show($slug) { $page = Page::where('slug', $slug)->first(); $courses = Course::published()->hasCategory()->orderBy('created_at', 'desc')->take(4)->get(); $articles = Article::published()->orderBy('published_at', 'desc')->take(2)->get(); return view('pages.show', ['page' => $page, 'latest_courses' => $courses, 'latest_articles' => $articles]); }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { parent::boot($router); $router->model('courses', 'App\\Course'); $router->bind('tags', function ($name) { return Tag::where('name', $name)->firstOrFail(); }); $router->bind('courses', function ($id) { return Course::published()->FindOrFail($id); }); }
public function show(Course $course) { if (Enroll::where(['course_id' => $course->id, 'user_id' => Auth::user()->id])->ongoing()->exists() and $course->published()) { $lecture = $course->lectures()->first(); $comments = $lecture->comments()->latest('created_at')->get(); return view('courses.course', compact('course', 'lecture', 'comments')); } return view('courses.show', compact('course')); }
public function index() { $courses = Course::published()->hasCategory()->orderBy('created_at', 'desc')->take(4)->get(); $articles = Article::published()->orderBy('published_at', 'desc')->take(2)->get(); return view('home', ['latest_courses' => $courses, 'latest_articles' => $articles]); }