Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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
Php 是否仅通过Laravel收集特定字段?_Php_Laravel - Fatal编程技术网

Php 是否仅通过Laravel收集特定字段?

Php 是否仅通过Laravel收集特定字段?,php,laravel,Php,Laravel,如何使用Laravel集合仅返回特定字段 例如: $stores = $this->stores->allStores(); 这将返回许多带有id、名称、描述、街道、城镇的商店 我只需要id,name 是否需要使用map或filter?您可以使用Laravel的方法获取如下特定字段: $stores = $this->stores->allStores()->pluck('id', 'name'); // Or if - To get an array in re

如何使用Laravel集合仅返回特定字段

例如:

$stores = $this->stores->allStores();
这将返回许多带有id、名称、描述、街道、城镇的商店

我只需要
id
name

是否需要使用
map
filter

您可以使用Laravel的方法获取如下特定字段:

$stores = $this->stores->allStores()->pluck('id', 'name');
// Or if - To get an array in result
$stores_arr = $this->stores->allStores()->pluck('id', 'name')->toArray();
希望这有帮助。

您可以使用Laravel的方法获取如下特定字段:

$stores = $this->stores->allStores()->pluck('id', 'name');
// Or if - To get an array in result
$stores_arr = $this->stores->allStores()->pluck('id', 'name')->toArray();
希望这对您有所帮助。

您可以使用
pluck()
方法:

$stores->pluck('id', 'name');
您可以使用
pluck()
方法:

$stores->pluck('id', 'name');

非常感谢。如果我想通过
map
filter
更新你的答案,你能更新你的答案吗?@我会回来的,你不应该使用
map
filter
,因为它们在另一种情况下使用。简单一点,
pluck()
正是为此而设计的。谢谢。如果我想通过
map
filter
更新你的答案,你能更新你的答案吗?@我会回来的,你不应该使用
map
filter
,因为它们在另一种情况下使用。保持简单,
pluck()
正是为此而设计的。