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