在 Laravel Blade 中的数组中搜索值

Search value in array in Laravel Blade

我是 Laravel 的初学者。

我在变量 $selectedProductFeatures 中有数组:

array:9 [▼
  0 => array:9 [▼
    "id" => 9
    "product_id" => 3
    "feature_id" => 1
    "key" => "price60"
    "description" => "60"
    "maxvalue" => "0.00"
    "minvalue" => "0.00"
    "created_at" => "2020-06-24T08:27:35.000000Z"
    "updated_at" => "2020-06-24T08:27:35.000000Z"
  ]
  1 => array:9 [▼
    "id" => 10
    "product_id" => 3
    "feature_id" => 1
    "key" => "price60_promo"
    "description" => "65"
    "maxvalue" => "0.00"
    "minvalue" => "0.00"
    "created_at" => "2020-06-24T08:27:35.000000Z"
    "updated_at" => "2020-06-24T08:27:35.000000Z"
  ]
  2 => array:9 [▼
    "id" => 11
    "product_id" => 3
    "feature_id" => 1
    "key" => "price90"
    "description" => "90"
    "maxvalue" => "0.00"
    "minvalue" => "0.00"
    "created_at" => "2020-06-24T08:27:35.000000Z"
    "updated_at" => "2020-06-24T08:27:35.000000Z"
  ]
  3 => array:9 [▼
    "id" => 12
    "product_id" => 3
    "feature_id" => 1
    "key" => "price90_promo"
    "description" => "95"
    "maxvalue" => "0.00"
    "minvalue" => "0.00"
    "created_at" => "2020-06-24T08:27:35.000000Z"
    "updated_at" => "2020-06-24T08:27:35.000000Z"
  ]
  4 => array:9 [▼
    "id" => 13
    "product_id" => 3
    "feature_id" => 1
    "key" => "countertop_length"
    "description" => "1000.00"
    "maxvalue" => "0.00"
    "minvalue" => "0.00"
    "created_at" => "2020-06-24T08:27:35.000000Z"
    "updated_at" => "2020-06-24T08:27:35.000000Z"
  ]
  5 => array:9 [▼
    "id" => 14
    "product_id" => 3
    "feature_id" => 1
    "key" => "countertop_type"
    "description" => "4"
    "maxvalue" => "0.00"
    "minvalue" => "0.00"
    "created_at" => "2020-06-24T08:27:35.000000Z"
    "updated_at" => "2020-06-24T08:27:35.000000Z"
  ]
  6 => array:9 [▼
    "id" => 15
    "product_id" => 3
    "feature_id" => 1
    "key" => "maintenance"
    "description" => "<p>konserwacja</p>"
    "maxvalue" => "0.00"
    "minvalue" => "0.00"
    "created_at" => "2020-06-24T08:27:35.000000Z"
    "updated_at" => "2020-06-24T08:27:35.000000Z"
  ]
  7 => array:9 [▼
    "id" => 16
    "product_id" => 3
    "feature_id" => 1
    "key" => "other_title"
    "description" => "tytuł inny"
    "maxvalue" => "0.00"
    "minvalue" => "0.00"
    "created_at" => "2020-06-24T08:27:35.000000Z"
    "updated_at" => "2020-06-24T08:27:35.000000Z"
  ]
  8 => array:9 [▼
    "id" => 17
    "product_id" => 3
    "feature_id" => 1
    "key" => "other_description"
    "description" => "<p>opis inny</p>"
    "maxvalue" => "0.00"
    "minvalue" => "0.00"
    "created_at" => "2020-06-24T08:27:35.000000Z"
    "updated_at" => "2020-06-24T08:27:35.000000Z"
  ]
]

return view('admin.products.view', ['selectedProductFeatures' =>$selectedProductFeatures->toArray(), 'productTypes' => $productTypeRepository->allEnables('name', $orderBy = 'asc', $with = []), 'fileCount' => 5, 'fileFolder' => 'products', 'fileId' => $id, 'product' => $this->model->findOrFail($id), 'categories' => $categories, 'taxVat' => $vatRepository->allEnables('value', 'asc'), 'page_title' => 'Produkty', 'page_breadcrumbs' => [['page' => route('product.index'), 'title' => 'Produkty'], ['page' => '#', 'title' => 'Edytuj produkt']]]);

我的 blade 文件:

<input type="text" name="price60" value="{{ $xxxx1 ?? old('price60') }}">
<input type="text" name="price90" value="{{ $xxxx2 ?? old('price90') }}">

在 price60 中,我需要显示数组的值(数组是动态的)。

"key" => "price60" -- this is name input "description" => "60" - this value to show.

结果我需要:

对于输入中的“key”=>“price90”和“description”=>“90”,我需要显示:

<input type="text" name="price90" value="90">

我怎样才能做到?

您需要使用 foreach blade method.

遍历数组

然后你需要 display the value 你需要的数组。

您的用例示例:

@foreach($selectedProductFeatures as $productFeatures)
   <input type="text" name="{{$productFeatures->key}}" value="{{$productFeatures->description}}">
@endforeach