/** * 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(); }
/** * 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'); }
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; }