public function AddProduct() { $title = $_POST["productTitle"]; $description = $_POST["productDescription"]; $price = $_POST["productPrice"]; $hasModels = $_POST["productHasModels"]; $category = $_POST["productCategory"]; $subcategory = $_POST["subCategorySelect"]; if (Input::hasFile("product_picture")) { $file = Input::file("product_picture"); $folder = '/images/'; $destinationPath = public_path() . $folder; $filename = str_random(6) . '_' . $file->getClientOriginalName(); $img_path = $folder . $filename; $uploadSuccess = $file->move($destinationPath, $filename); } $p_id = Product::AddProduct($title, $description, $price, $category, $subcategory, $img_path, $hasModels); if ($hasModels) { $count = 1; while (true) { if (Input::hasFile("modelPicture" . $count)) { $file = Input::file("modelPicture" . $count); $folder = '/productModels/'; $destinationPath = public_path() . $folder; $filename = str_random(6) . '_' . $file->getClientOriginalName(); $img_path = $folder . $filename; $uploadSuccess = $file->move($destinationPath, $filename); $modelTitle = $_POST["modelTitle" . $count]; echo $modelTitle; Product::AddProductModel($p_id, $img_path, $modelTitle); } else { break; } $count++; } } return Redirect::to("admin/edit_products"); }