Ejemplo n.º 1
0
 /**
  * Remove the specified resource from storage.
  *
  *
  * @return \Illuminate\Http\Response
  */
 public function recipe_list()
 {
     if (\Input::has('searchRecipes')) {
         $mode = \Input::get('searchRecipes');
         $term = \Input::get('searchQuery');
         if (!empty($mode)) {
             switch ($mode) {
                 case 1:
                     $recipes = \App\Recipe::where('name', 'Like', '%' . $term . '%')->with('ingredients')->get();
                     break;
                 case 2:
                     $recipes = \App\Recipe::whereHas('ingredients', function ($q) use($term) {
                         $q->where('name', 'like', '%' . $term . '%');
                     })->with('ingredients')->get();
                     break;
                 case 3:
                     $recipes = \App\Recipe::where('cooking_time', '<=', $term)->with('ingredients')->get();
                     break;
             }
         }
     } else {
         $recipes = \App\Recipe::take(3)->with('ingredients')->get();
     }
     return $recipes->toJson();
 }
Ejemplo n.º 2
0
 public function getIndex(Request $request)
 {
     // Get all the books "owned" by the current logged in users
     // Sort in descending order by id
     $recipes = \App\Recipe::where('user_id', '=', \Auth::id())->orderBy('id', 'DESC')->get();
     return view('recipes.index')->with('recipes', $recipes);
 }
Ejemplo n.º 3
0
 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;
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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);
         }
     }
 }
Ejemplo n.º 6
0
 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);
     }
 }
Ejemplo n.º 7
0
 /**
  * Apply a photo to the referenced recipe.
  *
  * @param integer $id
  * @param Request $request
  */
 public function addPhoto($id, Request $request)
 {
     // validate the request object
     // and compare this against the photo
     // and only allow these mime types
     $this->validate($request, ['photo' => 'required|mimes:jpg,jpeg,png,bmp']);
     // grab the uploaded file instance
     $file = $request->file('photo');
     // set up a defualt name
     $name = time() . $file->getClientOriginalName();
     // move the file to new location, pass in variable for name
     $file->move('recipes/photos', $name);
     // find the current recipe
     $recipe = Recipe::where('id', '=', $id)->first();
     // link current recipe to photo
     // and create a new photo (where the directory path is this)
     $recipe->photos()->create(['path' => "/recipes/photos/{$name}"]);
 }
Ejemplo n.º 8
0
 public function search(Request $request)
 {
     $token = $request->get('token');
     $recipes = Recipe::where('name', 'LIKE', '%' . $token . '%')->orWhere('category', 'LIKE', '%' . $token . '%')->orWhere('recipe', 'LIKE', '%' . $token . '%')->orWhere('author', 'LIKE', '%' . $token . '%')->orderBy('category')->orderBy('name')->paginate(env('RECIPE_PAGINATION_MAX'));
     return view('recipes.index')->with('recipes', $recipes);
 }
Ejemplo n.º 9
0
 public function browseMyRecipes()
 {
     $recipes = \App\Recipe::where('user_id', '=', \Auth::id())->orderBy('title')->get();
     return view('show')->with('recipes', $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]);
 }
Ejemplo n.º 11
0
 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');
 }
Ejemplo n.º 12
0
 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 postDelete(Request $request, $id)
 {
     $category = Category::find($id);
     if ($category != null) {
         if ($category->final == 1 && $category->type == 0) {
             Schema::drop($category->table_name);
             Product::where('category_id', $category->id)->delete();
         } elseif ($category->final == 1 && $category->type == 1) {
             Recipe::where('category_id', $category->id)->delete();
         } else {
             $sub_categories = Category::where('parent_id', $category->id)->get();
             if (count($sub_categories) > 0) {
                 $msg = "Нельзя удалить категорию \"" . $category->name . "\", так как она содержит другие подкатегории.";
                 return redirect('admin/category?type=' . $category->type)->with('msg', $msg);
             }
         }
         $category->delete();
         $msg = "Категория \"" . $category->name . "\" удалена.";
         return redirect('admin/category?type=' . $category->type)->with('msg', $msg);
     } else {
         $msg = "Категории с id = " . $id . " не существует.";
         return redirect('admin/category')->with('msg', $msg);
     }
 }