コード例 #1
0
 /**
  * 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');
 }
コード例 #2
0
 /**
  * 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']);
 }
コード例 #3
0
ファイル: Importer.php プロジェクト: jhansen69/7Days
 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";
 }
コード例 #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Store $request)
 {
     $ingredients = array_chunk($request->get('ingredients'), 3);
     $recipe = Recipe::create($request->only('name', 'description'));
     foreach ($ingredients as $ingredient) {
         $recipe->ingredients()->attach($ingredient[2], ['quantity' => $ingredient[0], 'unit' => $ingredient[1]]);
     }
     if ($request->file('imagePath')) {
         $cropSize = $request->get('cropSize');
         $img = Image::make($request->file('imagePath')->getRealPath());
         $img_name = str_random(15) . '.jpg';
         $img->fit(500)->save('img/recipes/' . $img_name);
         $recipe->imagePath = $img_name;
     } else {
         $recipe->imagePath = 'default.jpg';
     }
     $recipe->tags()->detach();
     foreach ($request->only('tags') as $tag_id) {
         $recipe->tags()->attach($tag_id);
     }
     $recipe->steps = json_encode($request->get('steps'));
     $recipe->save();
     return redirect()->route('recipe.index');
 }
コード例 #5
0
 public function processInsert(Request $request)
 {
     //validate user inputs. we need at least 1 ingredient, title and procedure
     $rules = ['data.title' => 'required', 'data.procedure' => 'required', 'data.ingred' => 'required_without:data.newIngred'];
     $messages = ['data.title.required' => 'Il titolo è richiesto!', 'data.procedure.required' => 'La procedura per la preparazione della ricetta è obbligatoria!', 'data.ingred.required_without' => 'E necessario almeno un ingrediente!'];
     $validator = Validator::make($request->all(), $rules, $messages);
     $errors = $validator->errors();
     $errors = json_decode($errors);
     if ($validator->fails()) {
         return response()->json(['message' => $errors], 422);
     }
     //this we will need to add in the new recipe
     $userid = Auth::user()->id;
     //insert the recipe values!
     $recipe = \App\Recipe::create(['title' => $request->data['title'], 'procedure' => $request->data['procedure'], 'user_id' => $userid]);
     //create new record into pivot table recipe-ingredient for each ingredient needed!
     foreach ($request->data['ingred'] as $ingr) {
         $ingrInDb = \App\Ingredient::where('name', '=', $ingr['name'])->first();
         $pivot = \App\Recipe_Ingredient::create(['recipe_id' => $recipe->id, 'ingredient_id' => $ingrInDb->id, 'quantity' => $ingr['quantity']]);
     }
 }
コード例 #6
0
ファイル: BookController.php プロジェクト: JGManuyag/blog
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $recipe = Request::all();
     Recipe::create($recipe);
     return redirect('recipes');
 }