Validation 如何在Laravel验证中返回ID的已验证值

Validation 如何在Laravel验证中返回ID的已验证值,validation,laravel-5,error-messaging,Validation,Laravel 5,Error Messaging,因此,我创建了循环生成的单选按钮: <div class="custom-control custom-radio guest-form"> @foreach(config('const.res_site') as $id => $res) <div class="form-radio"> <input class="custom-control-input" type="radio" onchange="otherResSit

因此,我创建了循环生成的单选按钮:

<div class="custom-control custom-radio guest-form">
    @foreach(config('const.res_site') as $id => $res)
    <div class="form-radio">
        <input class="custom-control-input" type="radio" onchange="otherResSite({{$id}})" id="{{$res}}" value="{{$id}}" 
            name="reservation_site" {{ old("reservation_site") == $id ? "checked" : "" }}>
        <label for="{{ $res }}" class="custom-control-label">{{ $res }}</label>
    </div>
    @endforeach
    <div class="otherField" id="ifOtherSite" class="otherSite" style="display: {{ old('reservation_site') == 4 ? 'display:inline-flex' : 'none' }}">
        <input type='text' class="form-control" id='otherSite' name='otherSite' value="{{ old('otherSite', '') }}"><br>
    </div>
</div>
@if ($errors->has('otherSite'))
    <div class="form-group">
        <p class="text-danger">{{ $errors->first('otherSite') }}</p>
    </div>
@endif
如果所选选项为“其他”,则此选项用于验证
otherSite
值。它现在工作正常,但返回的验证消息如下所示:

return [
    'reservation_site' => ['required'],
    'otherSite' => ['required_if:reservation_site,2'],
]
当预订站点为2时,需要“其他站点”字段

我的验证器如下所示:

return [
    'reservation_site' => ['required'],
    'otherSite' => ['required_if:reservation_site,2'],
]
现在,我如何将其返回消息设置为

当预订站点为“其他”时,需要“其他站点”字段


我有什么办法可以做到吗?

好的。如果有人有一天需要这个,我是这样做的:

 <input class="custom-control-input" type="radio" id="{{$res}}" value='{{$id == 4 ? "other" : $id}}'>
return [
        'reservation_site' => ['required'],
        'otherSite' => ['required_if:reservation_site,other'],
]