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