repository = $sanction; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Bixo\Sanction\Repositories\Criteria\SanctionResourceCriteria::class); } /** * Display a list of sanction. * * @return Response */ public function index(SanctionRequest $request) { return $this->repository ->setPresenter(\Bixo\Sanction\Repositories\Presenter\SanctionPresenter::class) ->paginate(); } /** * Display sanction. * * @param Request $request * @param Model $sanction * * @return Response */ public function show(SanctionRequest $request, Sanction $sanction) { return $sanction->setPresenter(\Bixo\Sanction\Repositories\Presenter\SanctionListPresenter::class); ; } /** * Create new sanction. * * @param Request $request * * @return Response */ public function store(SanctionRequest $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('sanction::sanction.name')]); $code = 204; $status = 'success'; $url = guard_url('sanction/sanction/' . $sanction->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('sanction/sanction'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the sanction. * * @param Request $request * @param Model $sanction * * @return Response */ public function update(SanctionRequest $request, Sanction $sanction) { try { $data = $request->all(); $sanction->update($data); $message = trans('messages.success.updated', ['Module' => trans('sanction::sanction.name')]); $code = 204; $status = 'success'; $url = guard_url('sanction/sanction/' . $sanction->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('sanction/sanction/' . $sanction->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the sanction. * * @param Model $sanction * * @return Response */ public function destroy(SanctionRequest $request, Sanction $sanction) { try { $sanction->delete(); $message = trans('messages.success.deleted', ['Module' => trans('sanction::sanction.name')]); $code = 202; $status = 'success'; $url = guard_url('sanction/sanction/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('sanction/sanction/' . $sanction->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); } }