27

I have foreach and inside foreach i have input like this:

 <input type="text" id="text-title" name="article_title[{{$language->code}}]" value="{{ old('article_title[$language->code]') }}" class="form_input"  />

Im trying to add old input like this but its not working. Any suggestion how can i use old for array?

Also i tried this but also not working:

  <input type="text" id="text-title" name="article_title[{{$language->code}}]" value="{{ old('article_title.0') }}" class="form_input"  />

I have validation only for first iteration if that means anything for you.

2 Answers 2

57

You should be able to access the index off of your language code:

value="{{ old('article_title.'.$language_code) }}"
Sign up to request clarification or add additional context in comments.

Comments

4

you can use the old to return old value as an array

# old('article_title') => array

value="{{ old('article_title')[0][$language_code] ?? "" }}"

# "0" is an example of an index. You can programmatically add index

2 Comments

Trying to access array offset on value of type null
@mercury ` value="{{ old('article_title')[0][$language_code] ?? "" }}" ` # "0" is an example of an index. You can programmatically add index

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.