コード例 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $chicken = new MenuItem();
     $chicken->name = "Chicken";
     $chicken->menu_id = 1;
     $chicken->save();
     $fish = new MenuItem();
     $fish->name = "Fish";
     $fish->menu_id = 1;
     $fish->save();
     $salad = new MenuItem();
     $salad->name = "Salad";
     $salad->menu_id = 1;
     $salad->save();
 }
コード例 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request, $eventId)
 {
     $input = Input::except('token');
     $menu = Menu::where('event_id', '=', $eventId)->first();
     $menuItem = new MenuItem();
     if (!$menu->id) {
         return $this->respondNotFound('Menu Not Found');
     }
     $validator = $menuItem->getValidator($input);
     if ($validator->fails()) {
         return $this->respondInvalidData($validator->errors());
     }
     $menuItem->fill($input);
     $menuItem->menu_id = $menu->id;
     $menuItem->save();
     return $this->respondCreateSuccess($menuItem->name . ' created');
 }
コード例 #3
0
ファイル: MenuController.php プロジェクト: verget/catering
 public function actionAddItems()
 {
     $request = Yii::$app->request;
     $items = json_decode($request->post('items'));
     foreach ($items as $item) {
         $model = new MenuItem();
         $model->item_id = $item;
         $model->menu_id = $request->post('menu');
         $model->save();
     }
     return true;
 }