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) { return $this->repository ->setPresenter(\Litepci\Probation\Repositories\Presenter\ProbationPresenter::class) ->paginate(); } /** * Display probation. * * @param Request $request * @param Model $probation * * @return Response */ public function show(ProbationRequest $request, Probation $probation) { return $probation->setPresenter(\Litepci\Probation\Repositories\Presenter\ProbationListPresenter::class); ; } /** * Create new probation. * * @param Request $request * * @return Response */ public function store(ProbationRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('probation::probation.name')]); $code = 204; $status = 'success'; $url = guard_url('probation/probation/' . $probation->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('probation/probation'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the probation. * * @param Request $request * @param Model $probation * * @return Response */ public function update(ProbationRequest $request, Probation $probation) { try { $data = $request->all(); $probation->update($data); $message = trans('messages.success.updated', ['Module' => trans('probation::probation.name')]); $code = 204; $status = 'success'; $url = guard_url('probation/probation/' . $probation->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('probation/probation/' . $probation->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the probation. * * @param Model $probation * * @return Response */ public function destroy(ProbationRequest $request, Probation $probation) { try { $probation->delete(); $message = trans('messages.success.deleted', ['Module' => trans('probation::probation.name')]); $code = 202; $status = 'success'; $url = guard_url('probation/probation/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('probation/probation/' . $probation->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }