Esempio n. 1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($tag_id = null)
 {
     if ($tag_id) {
         $recipes = Recipe::whereHas('tags', function ($query) use($tag_id) {
             $query->where('id', $tag_id);
         })->get();
     } else {
         $recipes = Recipe::all();
     }
     $tags = Tag::where('for', 'recipe')->get();
     $tag = Tag::find($tag_id);
     return view('recipes.index')->with(['recipes' => $recipes, 'tags' => $tags, 'the_tag' => $tag]);
 }
Esempio n. 2
0
 public function postSearch(Request $request)
 {
     $recipes = new \App\Recipe();
     if (empty($request->title) && empty($request->ingredient)) {
         \Session::flash('flash_message', 'Please enter a title or ingredient');
         return view('search');
     } elseif (!empty($request->title)) {
         if ($request->mineall == 'mine') {
             $recipes = \App\Recipe::where('title', 'LIKE', '%' . $request->title . '%')->where('user_id', '=', \Auth::id())->get();
         } else {
             $recipes = \App\Recipe::where('title', 'LIKE', '%' . $request->title . '%')->get();
         }
         return view('search')->with('recipes', $recipes);
     } else {
         $ingredient = $request->ingredient;
         if ($request->mineall == 'mine') {
             $recipes = \App\Recipe::whereHas('ingredients', function ($f) use($ingredient) {
                 $f->where('name', 'LIKE', '%' . $ingredient . '%');
             })->where('user_id', '=', \Auth::id())->get();
         } else {
             $recipes = \App\Recipe::whereHas('ingredients', function ($f) use($ingredient) {
                 $f->where('name', 'LIKE', '%' . $ingredient . '%');
             })->get();
         }
         ## if ingredient isn't found, search under other names
         if ($recipes->isEmpty()) {
             if ($request->mineall == 'mine') {
                 $recipes = \App\Recipe::whereHas('ingredients', function ($f) use($ingredient) {
                     $f->where('parallel_name', 'LIKE', '%' . $ingredient . '%');
                 })->where('user_id', '=', \Auth::id())->get();
             } else {
                 $recipes = \App\Recipe::whereHas('ingredients', function ($f) use($ingredient) {
                     $f->where('parallel_name', 'LIKE', '%' . $ingredient . '%');
                 })->get();
             }
         }
         $categoryIngredient = \App\Ingredient::where('name', '=', $ingredient)->first();
         if ($recipes->isEmpty() && isset($categoryIngredient)) {
             $category = $categoryIngredient->category;
             if ($request->mineall == 'mine') {
                 $recipes = \App\Recipe::whereHas('ingredients', function ($f) use($category) {
                     $f->where('category', '=', $category);
                 })->where('user_id', '=', \Auth::id())->get();
             } else {
                 $recipes = \App\Recipe::whereHas('ingredients', function ($f) use($category) {
                     $f->where('category', '=', $category);
                 })->get();
             }
             if ($recipes->isEmpty()) {
                 \Session::flash('flash_message', 'No recipes found with this ingredient');
                 return view('search');
             } else {
                 \Session::flash('flash_message', 'No recipes found with this ingredient - try using it in one of these');
                 return view('search')->with('recipes', $recipes);
             }
         }
     }
     if ($recipes->isEmpty()) {
         \Session::flash('flash_message', 'No recipes found with this ingredient');
         return view('search');
     }
     return view('search')->with('recipes', $recipes);
 }
Esempio n. 3
0
 /**
  * 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);
 }