Jquery 下拉条件验证-Don';t仅当在上一个下拉字段中选择了特定字段选项时,才需要下拉字段

Jquery 下拉条件验证-Don';t仅当在上一个下拉字段中选择了特定字段选项时,才需要下拉字段,jquery,laravel,validation,requiredfieldvalidator,Jquery,Laravel,Validation,Requiredfieldvalidator,在我的创建用户表单中,我有两个下拉字段,一个角色下拉列表和一个团队下拉列表。目前,角色字段是必需的,但团队字段不是。新用户可以是超级用户,因此不是团队的成员。这就是为什么团队字段最初不是必需的,但这是由于用户偶尔忘记添加团队而导致的一些问题,因此我们现在也需要将团队字段设置为必需的。因此,我需要的是一些条件验证,如果角色字段的所选下拉选项为“超级用户”,则不需要团队字段下拉列表,但如果所选角色字段为任何其他选项,则需要团队字段下拉列表。因此,我需要为除“超级用户”角色之外的所有选定角色设置下拉团

在我的创建用户表单中,我有两个下拉字段,一个角色下拉列表和一个团队下拉列表。目前,角色字段是必需的,但团队字段不是。新用户可以是超级用户,因此不是团队的成员。这就是为什么团队字段最初不是必需的,但这是由于用户偶尔忘记添加团队而导致的一些问题,因此我们现在也需要将团队字段设置为必需的。因此,我需要的是一些条件验证,如果角色字段的所选下拉选项为“超级用户”,则不需要团队字段下拉列表,但如果所选角色字段为任何其他选项,则需要团队字段下拉列表。因此,我需要为除“超级用户”角色之外的所有选定角色设置下拉团队字段

我原以为拉威尔的必修课是个好办法,但我所有尝试这个选项的尝试都失败了,但我很可能把它搞砸了。解决这一需求的最佳选择是什么。如何实现这一功能?一旦我需要团队字段,只要选择的角色下拉列表选项不是“超级用户”,就应该是必需的,但一旦选择了“超级用户”,那么团队下拉列表字段就不应该是必需的

我的代码:

StoreUsersRequest

 public function rules()
    {
        return [
            'name' => 'required',
            'email' => 'required|email|unique:users,email',
            'last_login_at' => 'nullable|date_format:'.config('app.date_format'),
            'role' => 'required',
            'role.*' => 'exists:roles,id',
        ];
    }
创建表单

        <div class="col-sm-4 form-group">
            @if(auth()->user()->role->contains(1))
            {!! Form::label('role', trans('global.users.fields.role').'*', ['class' => 'control-label']) !!}
            {!! Form::select('role[]', $roles, old('role'), ['class' => 'form-control', 'id' => 'selectall-role' , 'required' => '']) !!}
                <p class="help-block gray">@lang('global.app_see_description_of_user_roles_below').</p>
            @if($errors->has('role'))
                <p class="help-block">
                    {{ $errors->first('role') }}
                </p>
            @endif
        </div>

        <div class="col-sm-4 form-group">
            {!! Form::label('team_id', trans('global.users.fields.team').'', ['class' => 'control-label']) !!}
            {!! Form::select('team_id', $teams, old('team_id'), ['class' => 'form-control select2 autosetup',]) !!}
            <p class="help-block"></p>
            @if($errors->has('team_id'))
                <p class="help-block">
                    {{ $errors->first('team_id') }}
                </p>
            @endif
        </div>
    public function create()
    {
        $roletype = Role::where('id', '>', 1)->orderBy('display_order')->get();
        $roles = \App\Role::orderBy('display_order')->get()->pluck('title', 'id');
        $teams = \App\Team::select(DB::raw('concat (name," - ",city) as name,id'))->orderBy('name')->pluck('name', 'id')->prepend(trans('global.app_please_select'), '');

        $create_user = true;

        return view('admin.users.create', compact('roles', 'teams', 'roletype', 'create_user'));
    }