예제 #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //fetch 20 foods from database which are latest
     $foods = Food::with('brand')->orderBy('created_at', 'desc')->paginate(20);
     //page heading
     $title = 'Food list';
     //return foods.blade.php template from resources/views folder
     return view('foods.index')->withFoods($foods)->withTitle($title);
 }
예제 #2
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function getFoods(Request $request)
 {
     if ($request->input('q')) {
         $search_query = $request->input('q');
         $foods = Food::with('brand')->where('name', 'like', '%' . $search_query . '%')->get();
     } else {
         $foods = Food::with('brand')->get();
     }
     return response()->json($foods);
 }