<div class="mb-3 row">
    <label for="model_input" class="col-2 col-form-label fw-bold">@lang('model') : </label>
    <div class="col-10">
        <select name="model_id" id="model_input" class="form-select" disabled required>
            <option value="" @if(old('model_id') !== null) selected @endif>@lang('please_select')</option>
            @foreach($models as $model)
                <option
                    value="{{$model->id}}"
                    @if(old('model_id') !== null)
                        @if($model->id == old('model_id'))
                            selected
                       @endif
                    @else
                        @if(isset($data))
                            @if(!empty($data->model))
                                @if($model->id == $data->model->id)
                                    selected
                                @endif
                           @endif
                        @endif
                    @endif
                >
                    {{$model->name}}
                </option>
            @endforeach
        </select>
    </div>
</div>
<script>
    $("#brand_input").on( "input",function() {
        $('#model_input').prop("disabled", false);
        $('#model_input').children().remove().end();
        $('#model_input').append(`<option disabled selected value="">@lang('please_select')</option>`);
        let models = {!! json_encode($models) !!};
        models.forEach(function(item){
            if(item['brand_id'] == $('#brand_input').val()){
                $('#model_input').append(`<option value="` + item['id']  +`">` + item['name'] + `</option>`);
            }
        })
    });
    $("#model_input").on( "input",function() {
        $("#model_input option:contains('Vælg...')").remove();
    });
</script>