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();