Fred K
Fred K

Reputation: 13910

Laravel Blade: concatenating variables as string inside old() function

I'm trying to implement the old() on a bunch of checkboxes generated by 2 foreach (one with key $day_key and one with $period_key)

<input type="checkbox" 
  name="availability[{{ $day_key }}][{{ $period_key }}]" 
  {{ ( old('availability["'.$day_key.'"]["'.$period_key.'"]') == 'on' ) ? 'checked' : '' }} />

I need to print this string inside the old() function:

'availability["'.$day_key.'"]["'.$period_key.'"]'

but it doesn't work. How can I do it?

Upvotes: 2

Views: 395

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163768

The correct syntax is:

{{ old('availability')[$day_key][$period_key] === 'on' ? 'checked' : '' }}

Upvotes: 2

Related Questions