構成ファイルから配列を取得するドロップダウン フィールドを追加したいと考えています。私はこれを試しましたが、エラーが発生しました。
config/gallery.php で:
return [
'column_num' => [
''=>'-- Choose one --',
'one' => 'Category: One column',
'one-second'=> 'Category: Two columns',
'one-third'=> 'Category: Three columns',
'one-fourth'=> 'Category: Four columns',
'one-fifth'=> 'Category: Five columns',
'one-sixth'=> 'Category: Six columns',
],
];
app/PageTemplates.php 内
...
$this->crud->addField([
'name' => 'column_num',
'label' => 'Number of columns',
'type' => 'select_from_array',
'options' => config('gallery.column_num'),
'fake' => true,
'store_in' => 'extras',
]);
====== 更新 =====
エラー:
a1e88af9db4bb80b9055323bf64be621df2f9960.php 行 19 の ErrorException: 未定義のインデックス: 値 (View: /Users/sokada/Code/backpack-ceci/vendor/backpack/crud/src/resources/views/fields/select_from_array.blade.php) (View: / Users/sokada/Code/backpack-ceci/vendor/backpack/crud/src/resources/views/fields/select_from_array.blade.php) (ビュー: /Users/sokada/Code/backpack-ceci/vendor/backpack/crud/ src/resources/views/fields/select_from_array.blade.php) a1e88af9db4bb80b9055323bf64be621df2f9960.php の 19 行目 CompilerEngine->handleViewException(object(ErrorException), '1') PhpEngine.php の 44 行目
ドキュメントのようにこれを試しましたが、それでもエラーが発生します。
$this->crud->addField([
// select_from_array
'name' => 'template',
'label' => "Template",
'type' => 'select_from_array',
'options' => [‘one’ => ‘One’, ‘two’ => ‘Two’],
'allows_null' => false,
// 'allows_multiple' => true, // OPTIONAL; needs you to cast this to array in your model;
]);
エラー
PageTemplates.php 行 114 の ErrorException: 未定義の定数 'one' の使用 - PageTemplates.php 行 114 の HandleExceptions->handleError('8', '未定義の定数 'one' の使用 - '' と見なされる'' one''', '/Users/sokada/Code/backpack-ceci/app/PageTemplates.php', '114', array()) を PageTemplates.php の 114 行目に
このif文と関係があります。
<option value="{{ $key }}"
@if ((isset($field['value']) && $key==$field['value'])
|| ( ! is_null( old($field['name']) ) && old($field['name']) == $key)
|| (is_array($field['value']) && in_array($key, $field['value'])) )
selected
@endif
>{{ $value }}</option>