douyi6960 2019-04-22 14:13
浏览 42

双重foreach与html集体和采摘

in database I have products with custom features and custom feature values. For example product has a "wood type" and option value "oak". Each feature and feature value could have translations.

In database I have:

features 
- id
- few other fields (no matter)

feature_langs
- id_feature
- id_lang
- name

feature_values
- id
- few other fieds (no matter)

feature_value_langs
- id_feature_value
- id_lang
- name

And now in product edition I use htmlCollective and display 40x selects with multiple options and it looks like this: enter image description here

Problem is that with features loading page takes 1-1,8s randomly. Without that loading is close to 500-600ms.

For db query I use simply:

$features = Feature::with('translation')->get();
$featureValues = FeatureValue::with('translation')->get();

And form displaying:

    @forelse($features as $feature)
       <div class="form-group m-form__group row">
           <label class="col-2 col-form-label">{{ $feature->getName() }}</label>
           <div class="col-5">
{!! Form::select('featureValue',$featureValues->where('id_feature',$feature->id)->map(function ($setting) {
     return ['key' => $setting->getName(), 'value' => $setting->id];
    })->pluck('key', 'value')->prepend('Choose', '')->toArray(), null, array('class' => 'form-control')) !!}
           </div>
           </div>
   @empty
      No data
   @endforelse

Is there some bottleneck or I am missing something?

Many thanks for any help

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大