Level 15
<option ... selected="{{ old('author) === $author->id ? 'true' : 'false'" }}">
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a select element that looks like this
<select class="form-control" id="authorSelect1" name="author[1][author]" required>
<option value=""> -- </option>
@foreach ($authors as $author)
<option value="{{ $author->id }}" {{in_array($author->id, old("author") ?: []) ? "selected": ""}}>
{{ $author->name }}
</option>
@endforeach
</select>
with the option to add more dropdowns via js.
where my controller then looks like this
foreach ($request->author as $data) {
$newPost->authors()->attach($data['author']);
}
Laravel validation is working great with the rest of the form, but I can't work out how to get the old values back to each select if the form fails.
Can anyone help?
Please or to participate in this conversation.