Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     DB::transaction(function () use($request) {
         //1. Validation
         $this->validate($request, ['title' => 'required|unique:menu_translations', 'position' => 'required', 'type' => 'required', 'status' => 'required', 'parent_id' => 'numeric', 'ordering' => 'required|numeric']);
         //2. GET ALL REQUESTS AND CREATE MENU OBJECT
         $input = $request->all();
         if ($request->input('parent_id') == '') {
             $input = $request->except('parent_id');
         } else {
             $menuParent = Menu::find($request->input('parent_id'));
             $input['level'] = ++$menuParent->level;
         }
         $menu = new Menu($input);
         //3. SET CREATED USER TO THE MENU
         $menu->updatedBy()->associate(Auth::user());
         $menu->createdby()->associate(Auth::user());
         //4. SAVE MENU
         $menu->save();
         //$menuTranslations = new MenuTranslation($request->all());
         //$menu->menuTranslation()->save($menuTranslations);
         //3. INSERT INTO MENUS TABLE
         //Menu::create($input);
         //Menu::fill($input)->save();
         //5. FLASH MESSAGE BACK
         Session::flash('flash_message', 'Menu successfully added!');
         //6. REDIRECT BACK
     });
     return redirect()->back();
 }