/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $ingredient = new Ingredient(); $ingredient->name = $request->Name; $ingredient->supplier_id = $request->Supplier; $ingredient->quantity = $request->Quantity; $ingredient->unit = $request->Unit; $ingredient->save(); Activity::log('Add a new ingredient, ' . $ingredient->name . ', to the system.'); $request->session()->flash('status', 'Ingredient information was successfully saved.'); return Redirect::action('IngredientController@index'); }
public function create(Request $request) { if (!$this->isUnique($request->name)) { return Response::create("This already exists", 400); exit; } $ingredient = new Ingredient(); $ingredient->name = $request->name; $ingredient->quantity = $request->quantity; $ingredient->measure = $request->measure; $ingredient->save(); echo json_encode(true); exit; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $ingredient = new Ingredient(); $ingredient->fill($request->all()); $ingredient->user_id = Auth::id(); if ($request->hasFile('image')) { $file = $request->file('image'); $patch = config('files.ingredients.public_path'); $name = str_random(25) . '.' . $file->getClientOriginalExtension(); $image = $patch . $name; Image::make($file)->fit(config('files.ingredients.width'), config('files.ingredients.height'))->save($image); $ingredient->image = $image; } $ingredient->save(); Alert::success('messages.ingredient_created_successfully'); return redirect()->route('ingredients.edit', $ingredient); }
/** * Run the database seeds. * * @return void */ public function run() { $rpaprika = new App\Ingredient(); $rpaprika->name = 'Rode paprika'; $rpaprika->unit = 'stuks'; $rpaprika->type = 'groente'; $rpaprika->min_amount = 1; $rpaprika->save(); $grpaprika = new App\Ingredient(); $grpaprika->name = 'Groene paprika'; $grpaprika->unit = 'stuks'; $grpaprika->type = 'groente'; $grpaprika->min_amount = 1; $grpaprika->save(); $gpaprika = new App\Ingredient(); $gpaprika->name = 'Gele paprika'; $gpaprika->unit = 'stuks'; $gpaprika->type = 'groente'; $gpaprika->min_amount = 1; $gpaprika->save(); $aubergine = new App\Ingredient(); $aubergine->name = 'Aubergine'; $aubergine->unit = 'stuks'; $aubergine->type = 'groente'; $aubergine->min_amount = 1; $aubergine->save(); $courgette = new App\Ingredient(); $courgette->name = 'Courgette'; $courgette->unit = 'stuks'; $courgette->type = 'groente'; $courgette->min_amount = 1; $courgette->save(); $ui = new App\Ingredient(); $ui->name = 'Uien'; $ui->unit = 'stuks'; $ui->type = 'groente'; $ui->min_amount = 3; $ui->save(); $knoflook = new App\Ingredient(); $knoflook->name = 'Knoflook'; $knoflook->unit = 'stuks'; $knoflook->type = 'groente'; $knoflook->min_amount = 1; $knoflook->save(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(FoodFormRequest $request) { $data = $request->all(); $user_id = Auth::user()->id; $food = new Food(); $food->name = $request->get('name'); if (isset($data['compound_food'])) { $food->brand_id = 23; //brand name 'Homemade' } else { $food->brand_id = $request->get('brand'); } $food->kcal = $request->get('kcal'); $food->proteins = $request->get('proteins'); $food->carbs = $request->get('carbs'); $food->fats = $request->get('fats'); $food->fibre = $request->get('fibre'); $food->user_id = $request->user()->id; $food->save(); if (isset($data['compound_food']) && $data['compound_food']) { $last_inserted_id = $food->id; $ingredientsInArray = array(); $arrayId = $data['ingredient']; $arrayWeight = $data['ingredient-weight']; for ($i = 0; $i < count($arrayId); $i++) { $ingredientsInArray[$i]["ingredient_id"] = $arrayId[$i]; $ingredientsInArray[$i]["ingredient_weight"] = $arrayWeight[$i]; } foreach ($ingredientsInArray as $smallArray) { $ingredient = new Ingredient(); $ingredient->food_id = $last_inserted_id; $ingredient->ingredient_id = $smallArray['ingredient_id']; $ingredient->weight = $smallArray["ingredient_weight"]; $ingredient->user_id = $user_id; $ingredient->save(); } } $message = "Food has been successfully added"; return redirect('food/index')->withMessage($message); }
/** * Creates all recipe ingredients * * @param Request $request * @param int|string $recipeId */ private function saveIngredients(Request $request, $recipeId) { foreach ($request->get('ingredient') as $ingredient) { if (!$request->exists('amount-' . $ingredient)) { continue; } // creates new recipe ingredients if (is_numeric($ingredient)) { if (Ingredient::exists($ingredient) === false) { continue; } if ($request->exists('updateIngredient')) { DB::enableQueryLog(); if (in_array($ingredient, $request->get('updateIngredient'))) { $recipeIngredient = RecipeIngredient::where(function ($query) use($recipeId, $ingredient) { $query->where('recipe_id', '=', $recipeId)->where('ingredient_id', '=', $ingredient); })->first(); $recipeIngredient->amount = $request->get('amount-' . $ingredient); $recipeIngredient->save(); continue; } } $recipeIngredient = new RecipeIngredient(); $recipeIngredient->recipe_id = $recipeId; $recipeIngredient->ingredient_id = $ingredient; $recipeIngredient->amount = $request->get('amount-' . $ingredient); $recipeIngredient->save(); } else { $newIngredient = new Ingredient(); $newIngredient->name = ucfirst(str_replace('-', ' ', $ingredient)); if ($newIngredient->save()) { $recipeIngredient = new RecipeIngredient(); $recipeIngredient->recipe_id = $recipeId; $recipeIngredient->ingredient_id = $newIngredient->id; $recipeIngredient->amount = $request->get('amount-' . $ingredient); $recipeIngredient->save(); } } } }
public function update(Request $request, $id) { $product = Product::findOrFail($id); $allIngredients = Ingredient::get()->toArray(); $ingredientsInProduct = $product->ingredients->toArray(); $product->update($request->all()); foreach ($ingredientsInProduct as $ingredient) { if (array_search($ingredient['name'], $request->input('ingredient-list')) === false) { IngredientsInProduct::where('product_id', $id)->where('ingredient_id', $ingredient['id'])->delete(); } } foreach ($request->input('ingredient-list') as $inputIngredient) { if (is_int($this->ingredientSearch($inputIngredient, $ingredientsInProduct, 'name'))) { } elseif (is_int($this->ingredientSearch($inputIngredient, $allIngredients, 'name'))) { $attachIngredientToProduct = new IngredientsInProduct(); $attachIngredientToProduct->product_id = $id; $attachIngredientToProduct->ingredient_id = $allIngredients[array_search($inputIngredient, array_column($allIngredients, 'name'))]['id']; $attachIngredientToProduct->save(); } else { $newIngredient = new Ingredient(); $newIngredient->name = $inputIngredient; $newIngredient->unit = 'stuks'; $newIngredient->type = 'groente'; $newIngredient->min_amount = 1; $newIngredient->save(); $attachIngredientToProduct = new IngredientsInProduct(); $attachIngredientToProduct->product_id = $id; $attachIngredientToProduct->ingredient_id = $newIngredient->id; $attachIngredientToProduct->save(); } } return redirect()->action('ProductsController@edit', [$id])->with('status', 'Ingredient update is geslaagd!'); }
//echo $ingredientNew; $ingredientNew->save(); $idING = DB::table('ingredient')->where('nom', $ingredientNew->nom)->pluck('iding'); $composeNewing = new Compose(); $composeNewing->idrecette = $idrecette; $composeNewing->iding = $idING; $composeNewing->save(); //Quand aucune case n'est cochée, à améliorer if ($request->has('nom') == false) { return view('indexAppli', ['message' => 'Aucune case cochée ! Veuillez cocher au moins une case']); //return view('indexAppli'); } else { foreach ($request->input('nom') as $valeur) { $ingredient = new Ingredient(); $ingredient->nom = $valeur; $ingredient->save(); $iding = DB::table('ingredient')->where('nom', $valeur)->pluck('iding'); $compose = new Compose(); $compose->idrecette = $idrecette; $compose->iding = $iding; $compose->save(); } } if ($recette->save()) { return view('indexAppli', ['message' => 'Recette bien ajoutée !']); } else { return view('indexAppli', ['message' => 'Attention ! Il y a eu un problème dans ajout de la recette']); } }); Route::get('inscription', function () { return view('inscription');