repository = $course; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Dipendra\Programming\Repositories\Criteria\CourseUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(CourseRequest $request) { $courses = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('programming::course.names')); return $this->theme->of('programming::user.course.index', compact('courses'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Course $course * * @return Response */ public function show(CourseRequest $request, Course $course) { Form::populate($course); return $this->theme->of('programming::user.course.show', compact('course'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(CourseRequest $request) { $course = $this->repository->newInstance([]); Form::populate($course); $this->theme->prependTitle(trans('programming::course.names')); return $this->theme->of('programming::user.course.create', compact('course'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(CourseRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $course = $this->repository->create($attributes); return redirect(trans_url('/user/programming/course')) -> with('message', trans('messages.success.created', ['Module' => trans('programming::course.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Course $course * * @return Response */ public function edit(CourseRequest $request, Course $course) { Form::populate($course); $this->theme->prependTitle(trans('programming::course.names')); return $this->theme->of('programming::user.course.edit', compact('course'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Course $course * * @return Response */ public function update(CourseRequest $request, Course $course) { try { $this->repository->update($request->all(), $course->getRouteKey()); return redirect(trans_url('/user/programming/course')) ->with('message', trans('messages.success.updated', ['Module' => trans('programming::course.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(CourseRequest $request, Course $course) { try { $this->repository->delete($course->getRouteKey()); return redirect(trans_url('/user/programming/course')) ->with('message', trans('messages.success.deleted', ['Module' => trans('programming::course.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }