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