public function postCreateDish() { /* validate input */ $validator = Validator::make(Input::all(), array("name" => "required|unique:dishes", "price" => "required|integer", "description" => "required")); /* if validated */ if ($validator->passes()) { /* get input */ $dish = new Dish(); $dish->name = Input::get("name"); $dish->price = Input::get("price"); $dish->description = Input::get("description"); if (Input::has("new_category")) { $category = DishCategory::where("name", "=", Input::get("new_category"))->first(); if ($category) { $dish->dish_category_id = $category->id; } else { $category = new DishCategory(); $category->name = Input::get("new_category"); $category->save(); $dish->dish_category_id = $category->id; } } else { $dish->dish_category_id = Input::get("dish_category_id"); } $dish->save(); return Redirect::to('admin/dish/create_dish')->with('message', 'Dish added!')->with('dish', $dish); } else { return Redirect::to('admin/dish/create_dish')->withErrors($validator); } // end validation }
public function postCreateDish() { /* validate input */ $validator = Validator::make(Input::all(), array("name" => "required|unique:dishes", "price" => "required|numeric", "description" => "required")); /* if validated */ if ($validator->passes()) { $dish = new Dish(); $img = new DishImage(); $dish->name = Input::get('name'); $dish->description = Dish::nl2br(Input::get('description')); $dish->price = Input::get('price'); if (Input::hasFile('image')) { $destination = public_path() . "/upload-img"; $filename = md5(time()); $extension = Input::file('image')->getClientOriginalExtension(); Input::file('image')->move($destination, $filename . "." . $extension); } $dish->save(); if (Input::hasFile('image')) { $img->dish_id = $dish->id; $img->link = "/upload-img/" . $filename . "." . $extension; $img->save(); } return Redirect::to('admin/dishes/create')->with('message', "Successfully created a new dish!"); } else { return Redirect::to('admin/dishes/create')->with('message', "")->withErrors($validator); } // end validation }
public function run() { DB::table('dish_categories')->delete(); DB::table('dish_images')->delete(); DB::table('dishes')->delete(); $dishCategory = new DishCategory(); $dishCategory->name = "category1"; $dishCategory->save(); $dish = new Dish(); $dish->name = "Boiled Eggs"; $dish->dish_category_id = $dishCategory->id; $dish->price = 10; $dish->description = "this is item1 by country1"; $dish->save(); $dishImage = new DishImage(); $dishImage->dish_id = $dish->id; $dishImage->link = "http://besthomechef.com.au/wp/wp-content/uploads/2012/11/hard-boiled-eggs.jpg"; $dishImage->save(); $dishCategory = new DishCategory(); $dishCategory->name = "category2"; $dishCategory->save(); $dish = new Dish(); $dish->name = "Pancake"; $dish->dish_category_id = $dishCategory->id; $dish->price = 20; $dish->description = "this is item2 by country2"; $dish->save(); $dishImage = new DishImage(); $dishImage->dish_id = $dish->id; $dishImage->link = "http://besthomechef.com.au/wp/wp-content/uploads/2012/11/hard-boiled-eggs.jpg"; $dishImage->save(); $dishCategory = new DishCategory(); $dishCategory->name = "category3"; $dishCategory->save(); $dish = new Dish(); $dish->name = "Pasta Bolognese"; $dish->dish_category_id = $dishCategory->id; $dish->price = 30; $dish->description = "this is item3 by country3"; $dish->save(); $dishImage = new DishImage(); $dishImage->dish_id = $dish->id; $dishImage->link = "http://besthomechef.com.au/wp/wp-content/uploads/2012/11/hard-boiled-eggs.jpg"; $dishImage->save(); $dish = new Dish(); $dish->name = "Beef Stroganoff"; $dish->dish_category_id = $dishCategory->id; $dish->price = 30; $dish->description = "this is item3 by country3"; $dish->save(); $dishImage = new DishImage(); $dishImage->dish_id = $dish->id; $dishImage->link = "http://besthomechef.com.au/wp/wp-content/uploads/2012/11/hard-boiled-eggs.jpg"; $dishImage->save(); $dish = new Dish(); $dish->name = "Beef Wellington"; $dish->dish_category_id = $dishCategory->id; $dish->price = 30; $dish->description = "this is item3 by country3"; $dish->save(); $dishImage = new DishImage(); $dishImage->dish_id = $dish->id; $dishImage->link = "http://besthomechef.com.au/wp/wp-content/uploads/2012/11/hard-boiled-eggs.jpg"; $dishImage->save(); $dish = new Dish(); $dish->name = "Caesar Salad"; $dish->dish_category_id = $dishCategory->id; $dish->price = 30; $dish->description = "this is item3 by country3"; $dish->save(); $dishImage = new DishImage(); $dishImage->dish_id = $dish->id; $dishImage->link = "http://besthomechef.com.au/wp/wp-content/uploads/2012/11/hard-boiled-eggs.jpg"; $dishImage->save(); }