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