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