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