public function edit(Request $request, $id = null) { if ($id) { $this->model = $this->model->findOrFail($id); } if ($request->get('parent_id')) { $parent = $this->model->find($request->get('parent_id')); } //we create a new menu block $this->model->fill($request->input()); $this->model->application_id = \Soda::getApplication()->id; if (@$parent && !$this->model->id) { //create a new item and move it into a parent. //we need to move this item into the parent. $parent->addChild($this->model); } else { //otherwise, jsut assuem this is a root element I guess. $this->model->save(); } return redirect()->route('soda.' . $this->hint . '.view', ['id' => $this->model->id])->with('success', 'updated'); }