我想根据laravel的类别展示食物

I have a database table categories having columns:

  • Category_id
  • CategoryName

And other table is Food with:

  • Food_id
  • FoodName
  • Category_id

I want to show the food items according to category on webpage.
I'm using laravel 5.2 and I'm newbie.

Join those two tables and fetch the data, here is an example on how you do it without creating a model.

 $rows = DB::table('food')->select('food.food_id','food.foodName','categories.categoryName')->join('categories','categories.category_id','=','food.category_id')->where('categories.categoryName', '=', 'breakfast')->get();

you can remove the where('','','') part if you dont want to filter

good luck

You would create models for Food and Category. See here for the documentation: https://laravel.com/docs/5.2/eloquent If you then add relations between both models in those models you can just use Laravels lazy/eager loading to get your data.