mkirr
mkirr

Reputation: 81

Retrieving and passing data to form input

I have two DB tables as item and price.

In view file, foreach of items I have form element as

<input type="text" name="dc_{{$item->id}}" value="{{$price->dc_*}}">

I want * in value as dc_{{$item->id}} for an example like dc_4 or dc_7

I am unable to use {{ $price-> dc_{{$item->id}} }} for value as it is wrong syntax.

What's an alternative way to implement such logic?

Upvotes: 0

Views: 43

Answers (1)

chanafdo
chanafdo

Reputation: 5124

You can do

<input type="text" name="dc_{{ $item->id }}" value="{{ $price->{ 'dc_' . $item->id } }}">

Upvotes: 1

Related Questions