Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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:如何从列中获取现有ID的数组,稍后将在其中使用'where'`_Php_Sql_Laravel_Laravel 5 - Fatal编程技术网

Php Laravel:如何从列中获取现有ID的数组,稍后将在其中使用'where'`

Php Laravel:如何从列中获取现有ID的数组,稍后将在其中使用'where'`,php,sql,laravel,laravel-5,Php,Sql,Laravel,Laravel 5,考虑以下功能: public function index($countryCode, Request $request) { $invalidCountryTranslations = $countriesTranslation->whereIn('LanguageID', $arrayOfExistingIds)->get(); return view('admin.countriesTranslations.create', compact('countryCo

考虑以下功能:

public function index($countryCode, Request $request) {
    $invalidCountryTranslations = $countriesTranslation->whereIn('LanguageID', $arrayOfExistingIds)->get();
    return view('admin.countriesTranslations.create', compact('countryCode', 'languages', 'countriesTranslation'));
}
我使用上面的函数来找出哪些国家已经在表中(因此它不会被调用到视图中),因此基本上,
$arrayOfeExistingIDS
应该保存
LanguageID
列中的现有行

所以问题是,如何获取
LanguageID
列的现有数组

$arrayOfExistingIds=???
使用该方法

Pull方法检索给定键的所有值


正如Alexey告诉您的,使用
pulk()
方法,它将检索一个集合,如果您想要一个数组将其与
toArray()
all()
方法连接,就像这样

Model::take(5)->pluck("id")->toArray();
Model::take(5)->pluck("id")->all();
这将为您提供所需的阵列。 尽量不要使用
lists()
方法,因为它在5.2.0中已被弃用

Model::take(5)->pluck("id")->toArray();
Model::take(5)->pluck("id")->all();