timmaiers
timmaiers

Reputation: 11

Laravel Display Product name instead of ID

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

Answers (2)

Nims Patel
Nims Patel

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

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

Define a relationship:

public function product()
{
    return $this->belongsTo(Product::class);
}

And use it:

{{ $fd->purchase->product->name }}

Upvotes: 3

Related Questions