示例#1
0
文件: API.php 项目: asjs-dev/lab.coop
 protected function food()
 {
     if (!$this->session->status()) {
         return $this->_response("Authentication Required", 401);
     }
     $food = new Food();
     if ($this->method == 'GET') {
         if ($this->id) {
             return $food->getById($this->id);
         }
         return $food->getList();
     } else {
         if ($this->method == 'POST') {
             if ($this->data) {
                 return $food->create($this->data);
             }
         } else {
             if ($this->method == 'DELETE') {
                 if ($this->id) {
                     return $food->deleteById($this->id);
                 }
             }
         }
     }
     return "";
 }
示例#2
0
 public function run()
 {
     Food::truncate();
     Food::create(['name' => 'Oats, Rolled', 'protein' => '0.11', 'carbohydrate' => '0.604', 'fat' => '0.081']);
     Food::create(['name' => 'Soy Milk', 'protein' => '0.033', 'carbohydrate' => '0.06', 'fat' => '0.018']);
     Food::create(['name' => 'Banana', 'protein' => '0.011', 'carbohydrate' => '0.23', 'fat' => '0.003']);
 }
示例#3
0
 /**
  * Check name is exist in food table
  * return null if not exist
  * @param  $name name Vietnamese
  * @return  Food 
  */
 public function isAvaiableInFoodTable($name)
 {
     $slug = Utils::normalizeSlug($name);
     $sql = "select * from monan where slug = '" . $slug . "' limit 1";
     $query = mysql_query($sql);
     if (mysql_num_rows($query) > 0) {
         return Food::create(mysql_fetch_array($query));
     }
 }
示例#4
0
 public function add_post()
 {
     $valid = Validator::make(Input::all(), Food::$rule_add_food, Food::$food_langs);
     if ($valid->passes()) {
         $data = Input::all();
         $img = $data['food_image'];
         $isUpload = $img->move("uploads/food/images/", $img->getClientOriginalName());
         if ($isUpload) {
             $data = array("food_name" => Input::get("food_name"), "food_price" => Input::get("food_price"), "food_description" => Input::get("food_description"), "food_image" => $img->getClientOriginalName(), "food_created_at" => date("Y-m-d"));
             Food::create($data);
             return Redirect::route("manage_food_add_get")->with("flash_success", "Chúc mừng bạn đã thêm món ăn thành công");
         }
         return Redirect::route("manage_food_add_get")->with("flash_success", "Không thể upload ảnh");
     }
     return Redirect::route("manage_food_add_get")->withInput()->with("flash_error", $valid->errors()->first());
 }
示例#5
0
 public function create()
 {
     return Food::create($this->params);
 }