public function postEditDish($id) { /* 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 = Dish::find($id); $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/edit_dish/{$dish->id}")->with('message', 'Dish edited!'); } else { return Redirect::to("admin/dish/edit_dish/{$dish->id}")->withErrors($validator); } // end validation }
public static function formSelect() { $result = array(); foreach (DishCategory::all() as $category) { $result[$category->id] = $category->name; } return $result; }
public function initialize($entity = null, $options = null) { $category = new Select('categoryid', DishCategory::find(), array('using' => array('id', 'category'), 'useEmpty' => TRUE, 'emptyText' => 'Seleccione una Categoria')); $category->setLabel('Category'); $this->add($category); $gallery = new Select('galleryid', Gallery::find(), array('using' => array('id', 'name'), 'useEmpty' => TRUE, 'emptyText' => 'Seleccione una galeria')); $gallery->setLabel('Galeria'); $this->add($gallery); $name = new Text('name'); $name->setLabel('Name'); $this->add($name); $price = new Text('price'); $price->setLabel('Price'); $this->add($price); $image_path = new Text('image_path'); $image_path->setLabel('Image'); $this->add($image_path); $description = new TextArea('description'); $description->setLabel('Description'); $this->add($description); }
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(); }