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