Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel不检查html上数组中的选定项选择为多个功能_Laravel_Laravel 5 - Fatal编程技术网

Laravel不检查html上数组中的选定项选择为多个功能

Laravel不检查html上数组中的选定项选择为多个功能,laravel,laravel-5,Laravel,Laravel 5,使用此结果获取所选帖子的所有类别和用户选择的类别后: $content_categories = ContentCategories::all()->pluck('title', 'id'); Collection {#209 ▼ #items: array:3 [▼ 1 => "laravel" 2 => "nodejs" 3 => "php" ] } $selected_categories = $manage_content-&g

使用此结果获取所选帖子的所有类别和用户选择的类别后:

$content_categories = ContentCategories::all()->pluck('title', 'id');

Collection {#209 ▼
  #items: array:3 [▼
    1 => "laravel"
    2 => "nodejs"
    3 => "php"
  ]
}

$selected_categories = $manage_content->categories()->get()->pluck('title', 'id');

Collection {#223 ▼
  #items: array:2 [▼
    1 => "laravel"
    2 => "php"
  ]
}
我试图在html
select
上实现此结果,并在
$selected\u categories
中检查选中的项目,此代码仅显示
$content\u categories
,默认情况下不能检查带有
$selected\u categories
的项目

{{ 
  Form::select('categories[]', 
          $content_categories,
          $selected_categories, 
          array('multiple'=>'multiple'))
}}
结果:

<select class="multiselect-success" multiple="multiple" name="categories[]">
     <option value="1">laravel</option>
     <option value="2">nodejs</option>
     <option value="3">php</option>
</select>

拉维尔
nodejs
php

获取不带标题的选定类别的ID:

$selected_categories = $manage_content->categories()->pluck('id');
或者使用
keys()
仅获取密钥:

Form::select('categories[]', $content_categories, $selected_categories->keys(), array('multiple'=>'multiple'))

我认为,因为在
$content\u类别
$selected\u类别
中都有“laravel”和“php”。尝试将其更改为
$selected_categories
OP中的其他值。您是真的吗?拒绝了我的编辑,然后将我的编辑作为您自己的应用?@proeviz我很抱歉,先生,因为我在您的编辑后更新了帖子我没有选择更新代码后的项目使用
pulk('title','id')
->keys()
解决了我的问题,很高兴它有帮助。