Muhammad Ramzan Muhammad Ramzan - 1 year ago 69
Ajax Question

I want to show foods based on categories in 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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download