I have multiple columns which is saved with a suffix ended with the index of 1-12, such as savings_date_mth_1 until savings_date_mth_12. As of now, I would like to display this value on blade using for loop, but it cannot read the name of the column when I name it such as below.
@for ($i = 1; $i <= $savings->months_diff; $i++)
<div class="p-4 bg-gray-200 shadow-md hover:shadow-xl rounded-lg">
<div class="text-center text-gray-600 mb-2 underline">
{{ $savings->savings_date_mth_.$i }}
{{ \Carbon\Carbon::parse($savings->savings_date_mth_.$i)->format('M') }} Savings
</div>
<div>
Cost Item: 100
</div>
</div>
@endfor
I have tried using {$i} as well but it's not showing the value of the column still. Please enlighten me on this particular issue and what is the best practice for this.
$savings->{'savings_date_mth_' . $i}is what it ends up doing, but just be aware 🙂 - Tim Lewis