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