create() 공개 메소드

Create new menu
public create ( array $inputs ) : Menu
$inputs array attributes
리턴 Xpressengine\Menu\Models\Menu
예제 #1
0
 public function testCreate()
 {
     list($repo, $configs, $modules, $routes) = $this->getMocks();
     $instance = new MenuHandler($repo, $configs, $modules, $routes);
     $mockMenu = m::mock('Xpressengine\\Menu\\Models\\Menu');
     $mockMenu->shouldReceive('fill')->once()->with(['title' => 'test title', 'description' => 'test description']);
     $repo->shouldReceive('createModel')->andReturn($mockMenu);
     $repo->shouldReceive('insert')->with($mockMenu)->andReturn($mockMenu);
     $menu = $instance->create(['title' => 'test title', 'description' => 'test description']);
 }
예제 #2
0
 /**
  * store
  * 새로운 메뉴 생성을 처리하는 메소드
  *
  * @param MenuHandler $handler menu handler
  *
  * @return mixed
  * @throws Exception
  */
 public function store(MenuHandler $handler)
 {
     $desktopTheme = Input::get('theme_desktop');
     $mobileTheme = Input::get('theme_mobile');
     $rules = ['menuTitle' => 'required', 'theme_desktop' => 'required', 'theme_mobile' => 'required'];
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         Input::flash();
         return Redirect::back()->with('alert', ['type' => 'danger', 'message' => $validator->messages()]);
     }
     XeDB::beginTransaction();
     try {
         $menu = $handler->create(['title' => Input::get('menuTitle'), 'description' => Input::get('menuDescription'), 'siteKey' => Input::get('siteKey')]);
         $handler->setMenuTheme($menu, $desktopTheme, $mobileTheme);
         $this->permissionRegisterGrant($menu->getKey(), $handler->getDefaultGrant());
     } catch (Exception $e) {
         XeDB::rollback();
         Input::flash();
         return Redirect::back()->with('alert', ['type' => 'danger', 'message' => $e->getMessage()]);
     }
     XeDB::commit();
     return Redirect::route('settings.menu.index');
 }