Support the ongoing development of Laravel.io →
Database Eloquent

hi im with laravel 5.1

im trying to fetch data from table. categorys and products

categorys has following coloumns 

cat_name
cat_description
cat_price

products has following coloumns 

product_name
product_description
category   				//stores category id
product_price

in index.blade.php of product page. i want to dispaly content as follows

*product name          product description           category                   price* 

casio watch             an anolog watch               clock                      33$

Flash light             LED Flah light                lights                     42$
  1. i want to show to which category each product belongs to in category feild
  2. and as for the price,both product and category have price column. i want to display the addition result of the category price and product price. clock (its a category) has price of 24$ and casio watch (its product) 9$ in product listing, it should display 33$, by adding the values.

please help me in doing these. thank you

Last updated 3 years ago.
0

i am not doing the work/homework for you.. its a join/related query.. try it in the MySQL console and then go from there, if you get stuck on the query then post the query here..

or alternatively use relationship aspect of laravel to link categories/products and then construct a proper eloquent query using with() construct.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

rocky5469 rocky5469 Joined 21 Nov 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.