Chron
164
6
Laravel

Select inputs ignored by validation

Posted 1 month ago by Chron

How can I tell laravel to include select inputs in validation?

<div class="col-md-3">
    <div class="form-group">
        <label for="sex">Sex</label>
        <div class="input-group">
            <select name="sex" id="sex" class="form-control">
                <option selected disabled value="">Male or Female? </option>
                <option value="Male">Male</option>
                <option value="Female">Female</option>
            </select>
            @if ($errors->has('sex'))
                <span class="invalid-feedback" role="alert">
                    <strong>{{ $errors->first('sex') }}</strong>
                </span>
            @endif
        </div>
    </div>
</div>
$user = User::create(request()->validate([
    ...
    'sex' => ['required'],
]));

Please sign in or create an account to participate in this conversation.