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 store(Request $request) { $recipe = new Recipe(); $recipe->title = $request->input('title'); $recipe->description = $request->input('description'); $recipe->servings = $request->input('servings'); $recipe->prep_time = $request->input('prep_time'); $recipe->cook_time = $request->input('cook_time'); $recipe->save(); $ingredients = $request->input('ingredient'); $amounts = $request->input('amount'); $units = $request->input('unit'); $totalIngredients = count($ingredients); for ($i = 0; $i < $totalIngredients; $i++) { $recipeIngredient = new RecipeIngredient(); $recipeIngredient->create(['recipe_id' => $recipe->id, 'ingredient' => $ingredients[$i], 'amount' => $amounts[$i], 'unit' => $units[$i]]); } $order = 1; foreach ($request->input('step') as $step) { $recipeStep = new RecipeStep(); $recipeStep->create(['recipe_id' => $recipe->id, 'order' => $order, 'content' => $step]); $order++; } return redirect()->route('recipe.index'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { try { $fieldsNotToSet = ['id', 'created_at', 'updated_at']; $recipe = new Recipe(); $lstFields = $recipe::getFieldsModel(); $arrInfFields = []; foreach ($lstFields as $field) { if (in_array($field, $fieldsNotToSet)) { continue; } $valueField = $request->input($field); $arrInfFields[$field] = isset($valueField) ? $request->input($field) : ""; } $recipe->setFieldsSave($arrInfFields); $data = $recipe->save(); $statusCode = 200; $response = ["result" => $data, '_token' => csrf_token()]; } catch (\Exception $e) { $response = ["error" => $e->getMessage()]; $statusCode = 404; } finally { return Response::json($response, $statusCode); } }
public function create(Request $request) { $rateLimit = $this->rateLimit(); if ($rateLimit == false) { return response('Too Many Requests.', 429); } $code = ""; while (true) { $code = substr(md5(rand()), 0, 7); $data = DB::table('recipes')->where('code', $code)->get; if (empty($data)) { break; } } $recipe = new Recipe(); $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->code = $code; $recipe->save(); echo json_encode(true); exit; }
/** * Store a newly quick created resource in storage. * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ private function quickStore(Request $request) { $this->validate($request, ['name' => 'required|unique:recipes|max:255']); $recipe = new Recipe($request->all()); $recipe->slug = str_slug($request->get('name')); $recipe->user_id = Auth::user()->id; if ($recipe->save()) { return redirect('/recipes/edit/' . $recipe->slug)->with(['success' => ['Recept is aangemaakt. Je kan hier een beschrijving toevoegen.']]); } return redirect('/recipes')->with(['errors' => ['Sorry, er is iets fout gegaan. Probeer het opnieuw.']]); }
/** * 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); }
public function postAdd(Request $request) { $validator = $this->validator($request->all()); if ($validator->fails()) { return redirect()->back()->withErrors($validator->messages())->withInput(); } $recipe = new Recipe(); $recipe->name = $request->input('name'); $recipe->category_id = $request->input('category_id'); $recipe->description = $request->input('description'); $recipe->content = $request->input('content'); $file = $request->file('image'); $imageExtension = $file->getClientOriginalExtension(); $imageName = Slug::make($recipe->name) . '.' . $imageExtension; $request->file('image')->move(base_path() . '/public/images/recipes/', $imageName); $recipe->image = $imageName; $recipe->save(); $msg = "Рецепт \"" . $recipe->name . "\" добавлен."; return redirect('admin/recipe')->with('msg', $msg); }
public function store(Request $request) { $recipe = new Recipe(array('category' => $request->get('category'), 'name' => $request->get('name'), 'author' => $request->get('author'), 'recipe' => $request->get('recipe'))); $recipe->save(); Toastr::success('Recipe created.'); return redirect('/recipes'); }