/** * 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(); }