form = MenuForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litepie.menu.modules'), 'menu', guard_url('menu')); } /** * Display a list of menu. * * @return Response */ public function index(MenuResourceRequest $request) { $request = $request->all(); $page = MenuActions::run('paginate', $request); $data = new MenusCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('menu::menu.names')) ->view('menu::menu.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display menu. * * @param Request $request * @param Model $menu * * @return Response */ public function show(MenuResourceRequest $request, Menu $model) { $form = $this->form; $modules = $this->modules; $data = new MenuResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('menu::menu.name')) ->data(compact('data', 'form', 'modules')) ->view('menu::menu.show') ->output(); } /** * Show the form for creating a new menu. * * @param Request $request * * @return Response */ public function create(MenuResourceRequest $request, Menu $model) { $form = $this->form; $modules = $this->modules; $data = new MenuResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('menu::menu.name')) ->view('menu::menu.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new menu. * * @param Request $request * * @return Response */ public function store(MenuResourceRequest $request, Menu $model) { try { $request = $request->all(); $model = MenuAction::run('store', $model, $request); $data = new MenuResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('menu::menu.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('menu/menu/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/menu/menu')) ->redirect(); } } /** * Show menu for editing. * * @param Request $request * @param Model $menu * * @return Response */ public function edit(MenuResourceRequest $request, Menu $model) { $form = $this->form; $modules = $this->modules; $data = new MenuResource($model); // return view('menu::menu.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('menu::menu.name')) ->view('menu::menu.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the menu. * * @param Request $request * @param Model $menu * * @return Response */ public function update(MenuResourceRequest $request, Menu $model) { try { $request = $request->all(); $model = MenuAction::run('update', $model, $request); $data = new MenuResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('menu::menu.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('menu/menu/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('menu/menu/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the menu. * * @param Model $menu * * @return Response */ public function destroy(MenuResourceRequest $request, Menu $model) { try { $request = $request->all(); $model = MenuAction::run('destroy', $model, $request); $data = new MenuResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('menu::menu.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('menu/menu/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('menu/menu/' . $model->getRouteKey())) ->redirect(); } } }