repository = $admission; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\College\Admission\Repositories\Criteria\AdmissionResourceCriteria::class); } /** * Display a list of admission. * * @return Response */ public function index(AdmissionRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\College\Admission\Repositories\Presenter\AdmissionPresenter::class) ->$function(); } $admissions = $this->repository->paginate(); return $this->response->setMetaTitle(trans('admission::admission.names')) ->view('admission::admission.index', true) ->data(compact('admissions', 'view')) ->output(); } /** * Display admission. * * @param Request $request * @param Model $admission * * @return Response */ public function show(AdmissionRequest $request, Admission $admission) { if ($admission->exists) { $view = 'admission::admission.show'; } else { $view = 'admission::admission.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('admission::admission.name')) ->data(compact('admission')) ->view($view, true) ->output(); } /** * Show the form for creating a new admission. * * @param Request $request * * @return Response */ public function create(AdmissionRequest $request) { $admission = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('admission::admission.name')) ->view('admission::admission.create', true) ->data(compact('admission')) ->output(); } /** * Create new admission. * * @param Request $request * * @return Response */ public function store(AdmissionRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $admission = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('admission::admission.name')])) ->code(204) ->status('success') ->url(guard_url('admission/admission/' . $admission->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/admission/admission')) ->redirect(); } } /** * Show admission for editing. * * @param Request $request * @param Model $admission * * @return Response */ public function edit(AdmissionRequest $request, Admission $admission) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('admission::admission.name')) ->view('admission::admission.edit', true) ->data(compact('admission')) ->output(); } /** * Update the admission. * * @param Request $request * @param Model $admission * * @return Response */ public function update(AdmissionRequest $request, Admission $admission) { try { $attributes = $request->all(); $admission->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('admission::admission.name')])) ->code(204) ->status('success') ->url(guard_url('admission/admission/' . $admission->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('admission/admission/' . $admission->getRouteKey())) ->redirect(); } } /** * Remove the admission. * * @param Model $admission * * @return Response */ public function destroy(AdmissionRequest $request, Admission $admission) { try { $admission->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('admission::admission.name')])) ->code(202) ->status('success') ->url(guard_url('admission/admission/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('admission/admission/' . $admission->getRouteKey())) ->redirect(); } } /** * Remove multiple admission. * * @param Model $admission * * @return Response */ public function delete(AdmissionRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('admission::admission.name')])) ->status("success") ->code(202) ->url(guard_url('admission/admission')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/admission/admission')) ->redirect(); } } /** * Restore deleted admissions. * * @param Model $admission * * @return Response */ public function restore(AdmissionRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('admission::admission.name')])) ->status("success") ->code(202) ->url(guard_url('/admission/admission')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/admission/admission/')) ->redirect(); } } }