Reputation: 11
I want to display the Product name instead of just the Item id.
My code:
{{$fd->purchase->product_id}}
How can I change this? Because in my Feedback DB Table are only the Product ID?
How can I do this with the Laravel Database: Query Builder
?
Thanks
Upvotes: 0
Views: 1475
Reputation: 1056
First of define relationship between Purchase and Product
public function product()
{
return $this->belongsTo(App\Product);
}
And use its in view :
{{ $fd->purchase->product->product_name }}
Upvotes: 0
Reputation: 163748
Define a relationship:
public function product()
{
return $this->belongsTo(Product::class);
}
And use it:
{{ $fd->purchase->product->name }}
Upvotes: 3