repository = $course; parent::__construct(); } /** * Display a list of course. * * @return Response */ public function index(CourseRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('programming::course.names').' :: '); return $this->theme->of('programming::admin.course.index')->render(); } /** * Display a list of course. * * @return Response */ public function getJson(CourseRequest $request) { $pageLimit = $request->input('pageLimit'); $courses = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Dipendra\\Programming\\Repositories\\Presenter\\CourseListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $courses['recordsTotal'] = $courses['meta']['pagination']['total']; $courses['recordsFiltered'] = $courses['meta']['pagination']['total']; $courses['request'] = $request->all(); return response()->json($courses, 200); } /** * Display course. * * @param Request $request * @param Model $course * * @return Response */ public function show(CourseRequest $request, Course $course) { if (!$course->exists) { return response()->view('programming::admin.course.new', compact('course')); } Form::populate($course); return response()->view('programming::admin.course.show', compact('course')); } /** * Show the form for creating a new course. * * @param Request $request * * @return Response */ public function create(CourseRequest $request) { $course = $this->repository->newInstance([]); Form::populate($course); return response()->view('programming::admin.course.create', compact('course')); } /** * Create new course. * * @param Request $request * * @return Response */ public function store(CourseRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $course = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('programming::course.name')]), 'code' => 204, 'redirect' => trans_url('/admin/programming/course/'.$course->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show course for editing. * * @param Request $request * @param Model $course * * @return Response */ public function edit(CourseRequest $request, Course $course) { Form::populate($course); return response()->view('programming::admin.course.edit', compact('course')); } /** * Update the course. * * @param Request $request * @param Model $course * * @return Response */ public function update(CourseRequest $request, Course $course) { try { $attributes = $request->all(); $course->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('programming::course.name')]), 'code' => 204, 'redirect' => trans_url('/admin/programming/course/'.$course->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/programming/course/'.$course->getRouteKey()), ], 400); } } /** * Remove the course. * * @param Model $course * * @return Response */ public function destroy(CourseRequest $request, Course $course) { try { $t = $course->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('programming::course.name')]), 'code' => 202, 'redirect' => trans_url('/admin/programming/course/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/programming/course/'.$course->getRouteKey()), ], 400); } } }