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