public function getRecipes() { //Signature Base String //<HTTP Method>&<Request URL>&<Normalized Parameters> $base = rawurlencode("GET") . "&"; $base .= "http%3A%2F%2Fplatform.fatsecret.com%2Frest%2Fserver.api&"; //sort params by abc....necessary to build a correct unique signature $params = "format=json&"; $params .= "max_results=50&"; $params .= "method=recipes.search&"; $params .= "oauth_consumer_key=c1f69a4b6440454296fd1061870343a3&"; // ur consumer key $params .= "oauth_nonce=123&"; $params .= "oauth_signature_method=HMAC-SHA1&"; $params .= "oauth_timestamp=" . time() . "&"; $params .= "oauth_version=1.0&"; $params .= "page_number=0&"; $params .= "search_expression=healthy"; $params2 = rawurlencode($params); $base .= $params2; //encrypt it! $sig = base64_encode(hash_hmac('sha1', $base, "8b7c290389fb484ea628384704941110&", true)); // replace xxx with Consumer Secret //now get the search results and write them down $url = "http://platform.fatsecret.com/rest/server.api?" . $params . "&oauth_signature=" . rawurlencode($sig); $food_feed = file_get_contents($url); $arrays = json_decode($food_feed); foreach ($arrays as $array) { foreach ($array->recipe as $recipe) { $update = new Recipe(); $update->recipe_id = $recipe->recipe_id; $update->save(); } } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function AddStore(Request $request) { $recipe = new Recipe(); $recipe->product_id = $request->product_id; $recipe->ingredient_id = $request->Ingredient; $recipe->quantity = $request->Quantity; $recipe->save(); $product = Product::find($recipe->product_id); $ingredient = Ingredient::find($recipe->ingredient_id); Activity::log('Added ' . $ingredient->name . ' to the ' . $product->name . ' recipe.'); return Redirect::action('RecipeController@show', $request->product_id); }
/** * Run the recipe table seeds. * * @return void */ public function run() { Eloquent::unguard(); Recipe::create(['id' => 1, 'name' => 'Chocolate Chip Cookie', 'user_id' => 1, 'description' => 'Moist and chewy', 'ingredients' => '1 cup sugar, 1 cup flour, 1 cup chocolate chips', 'instructions' => 'Mix ingredients together in a bowl', 'notes' => 'Chill dough beforehand', 'cook_time' => 10, 'cook_time_type' => 'minutes']); Recipe::create(['id' => 2, 'name' => 'Special Brownies', 'user_id' => 1, 'description' => 'Chocolatey and dense', 'ingredients' => '1 cup sugar, 1 cup flour, 1 cup cocoa', 'instructions' => 'Mix ingredients together in a bowl', 'notes' => 'add walnuts if desired', 'cook_time' => 10, 'cook_time_type' => 'minutes']); Recipe::create(['id' => 3, 'name' => 'Vanilla Cake', 'user_id' => 1, 'description' => 'If you like vanilla, this is for you!', 'ingredients' => '1 cup sugar, 1 cup flour, 1 tsp pure vanilla extract', 'instructions' => 'Mix ingredients together in a bowl', 'notes' => 'Ice cake once room temperature', 'cook_time' => 10, 'cook_time_type' => 'minutes']); }
public function getHome() { $dates = []; $recipes = Recipe::all(); for ($i = 0; $i < 7; $i++) { array_push($dates, Carbon::now()->startOfWeek()->addDays($i)); } $datas = Day::whereBetween('date', array($dates[0], end($dates)))->get(); foreach ($dates as $key => $date) { if ($datas->whereLoose('date', $date)->first() != '') { $day = $datas->whereLoose('date', $date)->first(); } else { $day = Day::create(['date' => $date]); } $dates[$key] = $day; } $ingredients_list = collect(); foreach ($dates as $day) { foreach ($day->recipes as $recipe) { foreach ($recipe->ingredients as $ingredient) { if ($ingredients_list->where('id', $ingredient->id)->first() && $ingredients_list->where('id', $ingredient->id)->first()->pivot->unit == $ingredient->pivot->unit) { $ingredients_list->where('id', $ingredient->id)->first()->total += $ingredient->pivot->quantity; } else { $ingredients_list->push($ingredient); $ingredients_list->where('id', $ingredient->id)->first()->total = $ingredient->pivot->quantity; } } } } $supply = Auth::user()->ingredients; return view('page.home')->with(['days' => $dates, 'ingredients_list' => $ingredients_list, 'supply' => $supply]); }
public function parseRecipe($recipes, $userid, $alpha) { $processed = 0; foreach ($recipes['recipe'] as $item) { $data = $item['@attributes']; if ($data['name'] != '') { if (isset($data['craft_area'])) { $area = $data['craft_area']; } else { $area = ''; } if (isset($data['craft_tool'])) { $tool = $data['craft_tool']; } else { $tool = ''; } if (isset($data['craft_exp_gain'])) { $craftxp = $data['craft_exp_gain']; } else { $craftxp = 2; } if (isset($data['learn_exp_gain'])) { $learnxp = $data['learn_exp_gain']; } else { $learnxp = 20; } $record = array('name' => $data['name'], 'count' => $data['count'], 'craft_xp' => $craftxp, 'learn_xp' => $learnxp, 'craft_area' => $area, 'craft_tool' => $tool, 'craft_time' => $data['craft_time'], 'scrapable' => $data['scrapable'], 'user_id' => $userid, 'alpha' => $alpha, 'core' => 1); \App\Recipe::create($record); $processed++; } } return "Imported {$processed} recipes"; }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $input = Request::all(); Recipe::create($input); \Session::flash('flash_message', 'Your recipe has been stored!'); return redirect('recipes'); }
public function update(Request $request) { $recipe = Recipe::find($request->id); $recipe->name = $request->name; $recipe->prep_time = $request->prep_time; $recipe->cook_time = $request->cook_time; $recipe->serving_size = $request->serving_size; $recipe->instructions = $request->instructions; $recipe->save(); foreach ($request->ingredients as $item) { if (isset($item['ri_id'])) { $recipeIngrediet = RecipeIngredient::find($item['ri_id']); $recipeIngrediet->unit = $item['unit']; $recipeIngrediet->ingredient_id = $item['id']; $recipeIngrediet->save(); } else { $recipeIngrediet = new RecipeIngredient(); $recipeIngrediet->unit = $item['unit']; $recipeIngrediet->recipe_id = $request->id; $recipeIngrediet->ingredient_id = $item['id']; $recipeIngrediet->save(); } } echo json_encode(true); exit; }
public function search(Request $request) { $name = $request->input('name'); if (!$name) { return response("Please specify a search field", 400); } $results = Recipe::where('name', 'ILIKE', '%' . $name . '%')->get(); return $results; }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { parent::boot($router); $router->bind('recipes', function ($id) { return \App\Recipe::published()->findOrFail($id); }); $router->bind('tags', function ($name) { return \App\Tag::where('name', $name)->firstOrFail(); }); }
function ingredientsFromString($str, Recipe $recipe) { $ingredients = explode(',', $str); foreach ($ingredients as $ingredient) { $ingToSave = \App\Ingredient::where('name', '=', trim($ingredient))->first(); ## Check singular form if necessary if (!isset($ingToSave)) { $ingToSave = \App\Ingredient::where('name', '=', trim(str_singular($ingredient)))->first(); } ## Links ingredient to recipe, or adds new ingredient and links if (isset($ingToSave)) { $recipe->ingredients()->save($ingToSave); } else { $newIng = new \App\Ingredient(); $newIng->name = $ingredient; $newIng->save(); $recipe->ingredients()->save($newIng); } } }
/** * Run the database seeds. * * @return void */ public function run() { $recipes = ['baked potatoes with wild mushroom ragù' => ['potatoTest'], 'Buttermilk, Cornmeal Pancakes with Corn Salsa' => ['cornTest'], 'Thai Basil Eggplant' => ['eggplantTest']]; foreach ($recipes as $title => $ingredients) { $recipe = \App\Recipe::where('title', 'like', $title)->first(); foreach ($ingredients as $ingredient) { $ingredientName = \App\Ingredient::where('name', 'LIKE', $ingredient)->first(); $recipe->ingredients()->save($ingredientName); } } }
/** * Run the database seeds. * * @return void */ public function run() { $recipes = ['Vegetable Samosa' => ['dryFruits', 'vegetables', 'spices', 'oil', 'paneer'], 'Thandai' => ['milk', 'cream', 'dryFruits'], 'Paneer Masala' => ['milk', 'cream', 'dryFruits', 'paneer'], 'Daal Makhni' => ['cream', 'spices'], 'Faluda Malai Kulfi' => ['dryFruits', 'milk', 'cream'], 'Boondi Raita' => ['yogurt', 'vegetables', 'dryFruits'], 'Garlic Naan' => ['flour', 'yogurt', 'oil']]; foreach ($recipes as $recipe_name => $specifics) { $recipe = \App\Recipe::where('recipe_name', 'like', $recipe_name)->first(); foreach ($specifics as $specificName) { $specific = \App\Specific::where('name', 'LIKE', $specificName)->first(); $recipe->specifics()->save($specific); } } }
public function postDelete(Request $request, $id) { $recipe = Recipe::where('id', $id)->first(); if ($recipe != null) { $recipe->delete(); $msg = "Рецепт \"" . $recipe->name . "\" удален."; return redirect('admin/recipe')->with('msg', $msg); } else { $msg = "Рецепта с id = " . $id . " не существует."; return redirect('admin/recipe')->with('msg', $msg); } }
public function store($id, Request $request) { //get recipe $recipe = Recipe::whereId($id)->first(); // create the comment $comment = Comment::create(['body' => $request['body'], 'recipe_id' => $recipe->id, 'user_id' => Auth::user()->id]); // check if review exists if (isset($request['rating'])) { // create the new review $review = Review::create(['rating' => $request['rating'], 'user_id' => Auth::user()->id, 'recipe_id' => $recipe->id, 'comment_id' => $comment->id]); // attach the review to the comment $comment->review_id = $review->id; // save comment to include review_id $comment->save(); // sum of the reviews for current recipe $average = DB::table('reviews')->where('recipe_id', $recipe->id)->avg('rating'); //set the avg_rating attribute of the recipe to equal the value of the $average rounded to the nearest decimal $recipe->avg_rating = round($average, 2); // save recipe $recipe->save(); } //return view return redirect("/recipes/{$recipe->id}"); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $recipe = Recipe::find($id); Activity::log('Deleted an ingredient from the recipe.'); $recipe->delete(); return Redirect::back()->with('status', 'Ingredient removed!'); }
/** * Destroys a recipe record in the Recipes database. * * @param Recipe $recipe * @return mixed */ public function destroy(Recipe $recipe) { // delete the recipe record $recipe->delete(); flash()->success('Heads up', 'Your recipe has been successfully deleted.'); // return a view return redirect('recipes'); }
public function getRecipes(Request $request, $subcategory = null) { if ($subcategory == null) { if (null != $request->input('id')) { $recipe = Recipe::where('id', $request->input('id'))->first(); if ($recipe == null) { return redirect('recipes'); } return view('home.recipe')->with('recipe', $recipe); } $categories = Category::where('parent_id', null)->where('type', 1)->paginate(6); //->get(); return view('home.categories')->with(['categories' => $categories, 'pageTitle' => 'Рецепты']); } else { $parent = Category::where('table_name', $subcategory)->first(); if ($parent == null) { return redirect('recipes'); } if ($parent->final == 0) { $categories = Category::where('parent_id', $parent->id)->paginate(6); //->get(); return view('home.categories')->with(['categories' => $categories, 'pageTitle' => $parent->name]); } else { $recipes = Recipe::where('category_id', $parent->id)->paginate(6); //->get(); return view('home.recipes')->with(['recipes' => $recipes, 'pageTitle' => $parent->name]); } } }
public function getDelete($id) { $beer = \App\Beer::find($id); $recipe = \App\Recipe::where('beer_id', $id)->get(); foreach ($recipe as $item) { $item->delete(); } $beer->delete(); \Session::flash('flash_message', $beer->name . ' was deleted.'); return redirect('/beer'); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $userid = \Auth::id(); $recipe = \App\Recipe::findOrFail($id); $starredList = \App\Recipe::whereHas('users', function ($q) use($userid) { $q->where('users.id', '=', $userid); //echo'here'; })->get(); $ingredients = $recipe->ingredients()->get(); return \View::make('recipes.show')->withRecipe($recipe)->withStarredRecipe($starredList)->withIngredients($ingredients); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $recipe = Recipe::findOrFail($id); $recipe->destroy($id); return redirect('/recipes'); }
public function search(Request $request) { //validate user input. $rules = ['search' => 'min:3|required']; $messages = ['search.min' => 'Devi inserire almeno 3 caratteri da cercare!', 'search.required' => 'Devi inserire almeno 3 caratteri da cercare!']; $validator = Validator::make($request->all(), $rules, $messages); $errors = $validator->errors(); if ($validator->fails()) { return redirect()->route('recipes')->withErrors($errors); } //queries $recipesMatches = \App\Recipe::where('title', 'like', '%' . $request->search . '%')->orWhere('procedure', 'like', '%' . $request->search . '%')->get(); $usersMatches = \App\User::where('name', 'like', '%' . $request->search . '%')->orWhere('email', 'like', '%' . $request->search . '%')->get(); $ingredientsMatches = \App\Ingredient::where('name', 'like', '%' . $request->search . '%')->get(); $searchInput = $request->search; //highlight what we have found! foreach ($ingredientsMatches as $ingredient) { if (stripos($ingredient->name, $searchInput) !== false) { $ingredient->name = substr_replace($ingredient->name, '<b class="highlight">' . $searchInput . '</b>', stripos($ingredient->name, $searchInput), strlen($searchInput)); } } foreach ($recipesMatches as $recipe) { if (stripos($recipe->title, $searchInput) !== false) { $recipe->title = substr_replace($recipe->title, '<b class="highlight">' . $searchInput . '</b>', stripos($recipe->title, $searchInput), strlen($searchInput)); } if (stripos($recipe->procedure, $searchInput) !== false) { $recipe->procedure = substr_replace($recipe->procedure, '<b class="highlight">' . $searchInput . '</b>', stripos($recipe->procedure, $searchInput), strlen($searchInput)); } } foreach ($usersMatches as $user) { if (stripos($user->name, $searchInput) !== false) { $user->name = substr_replace($user->name, '<b class="highlight">' . $searchInput . '</b>', stripos($user->name, $searchInput), strlen($searchInput)); } if (stripos($user->email, $searchInput) !== false) { $user->email = substr_replace($user->email, '<b class="highlight">' . $searchInput . '</b>', stripos($user->email, $searchInput), strlen($searchInput)); } } return view('results', ['ingredientsMatches' => $ingredientsMatches, 'recipesMatches' => $recipesMatches, 'usersMatches' => $usersMatches, 'searchInput' => $request->search]); }
public function generate() { $dates = []; $recipes = Recipe::all(); for ($i = 0; $i < 7; $i++) { array_push($dates, Carbon::now()->startOfWeek()->addDays($i)); } $datas = Day::whereBetween('date', array($dates[0], end($dates)))->get(); foreach ($dates as $date) { if ($datas->whereLoose('date', $date)->first() != '') { $day = $datas->whereLoose('date', $date)->first(); $day->recipes()->detach(); $day->recipes()->attach($recipes->random()->id); } else { $day = Day::create(['date' => $date]); $day->recipes()->attach($recipes->random()->id); } } return redirect('/'); }
/** *delete */ public function getDoDelete($recipe_id) { $recipe = \App\Recipe::find($recipe_id); if (is_null($recipe)) { \Session::flash('flash_message', 'Recipe not found.'); return redirect('\\recipes'); } if ($recipe->specifics()) { $recipe->specifics()->detach(); } $recipe->delete(); \Session::flash('flash_message', $recipe->recipe_name . ' was deleted.'); return redirect('/recipes'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // Recipe::find($id)->delete(); return redirect('recipes'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Recipe::destroy($id); RecipeIngredient::where('recipe_id', $id)->delete(); RecipeStep::where('recipe_id', $id)->delete(); return redirect()->route('recipe.index'); }
/** * Compose the navigation bar. * */ private function composeNavigation() { view()->composer('layouts.nav', function ($view) { $view->with('latest', Recipe::latest()->first()); }); }
public function getSecret() { $data['recipe'] = Recipe::find(1); $data['recipe']['ingredients'] = Ingredient::where('recipe_id', '=', Recipe::find(1)->id)->get(); return response()->json($data); }
public function show($id = null) { $recipe = \App\Recipe::find($id); $ingredients = $recipe->ingredients()->get(); $ingString = ''; foreach ($ingredients as $ingredient) { $ingString .= $ingredient->name . ','; } $ingString = chop($ingString, ', '); return view('show')->with(['singleRecipe' => $recipe, 'ingredientString' => $ingString]); }
public function recipePdf($id) { $recipe = Recipe::whereId($id)->firstOrFail(); $view = view('reports.recipe')->with('vm', $recipe); $contents = $view->render(); SELF::html2pdf($contents); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $recipe = Recipe::find($id); $recipe->delete(); return redirect()->route('recipe.index'); }