dpnvrt3119 2016-07-18 12:13
浏览 12
已采纳

我想根据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.

  • 写回答

2条回答 默认 最新

  • doutizhou5312 2016-07-18 13:06
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记