Saving selected option after validation in Laravel

I need help with saving a selected option after validation fails.

Here is main.blade.php

<form method="POST" action="">
<select id="searchEngine" name="searchEngine">
<option value="google">Google</option>
<option value="bing">Bing</option>
<option value="duckduck">DuckDuckGo</option>
</select>

@if ($errors->has('searchEngine'))
<div style="background-color: #faa;">
@foreach ($errors->all() as $error)

@endforeach
</div>
@endif
</form>

Controller looks like:

request()->validate(
['searchEngine' => "required|in:google,duckduck"],
['searchEngine.in' => $searchEngine.' not working, try another']
);

I tried this, but it always returns only the last option:

<option value="google" {!! $errors->has('searchEngine') ? 'selected' : '' !!}>Google</option>
<option value="bing" {!! $errors->has('searchEngine') ? 'selected' : '' !!}>Bing</option>
<option value="duckduck" {!! $errors->has('searchEngine') ? 'selected' : '' !!}>DuckDuckGo</option>


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/34eWtpO
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time