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