There is an important difference between fetching a relationship with parentheses "$this->relationship()" or without '$this->relationship".
$this->relationship() return a query builder object where you can append conditions like where, whereHas etc. before executing the query with first(), get() etc.
$this->relationship returns the result of the query directly.
So in you're case you have to do:
return $this->Product_Category[0]->price;
Because you want the price of the query result and not the price of a query builder object.
And because Product_Category is a collection (HasMany Relation), you have to take an item out of the collection first.
Thank you thiver.. my bad, i didnt mentioned what is wanna do exactly sorry im very new to laravel can you please help doing the following
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$
please help me in doing these. thank you
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community