Laravel Lumen 中的查询生成器
Laravel Query Builder in Lumen
当我将 Laravel 的查询生成器用于带有 MySQL 数据库的 Lumen 应用程序时,它没有按预期工作。我用过:
$itemid = DB::table('table1')->where('UserID','=',1)->pluck('ID');
这只有returns一个值。这里有什么错误?
尝试
$itemid = DB::table('table1')->where('UserID','=',1)->get()->pluck('ID');
在这里您可以阅读更多有关在查询中使用 pluck 时发生这种情况的原因
Pluck together with first using Query builder
更新:
我忘记了 DB::table returns 数组,所以:
$items = DB::table('table1')->where('UserID','=',1)->get();
$itemsById = array_pluck($items, 'ID');
使用 first 而不是 get 作为获取 return 数组。
$itemid = DB::table('table1')->where('UserID','=',1)->first()->pluck( 'ID');
当我将 Laravel 的查询生成器用于带有 MySQL 数据库的 Lumen 应用程序时,它没有按预期工作。我用过:
$itemid = DB::table('table1')->where('UserID','=',1)->pluck('ID');
这只有returns一个值。这里有什么错误?
尝试
$itemid = DB::table('table1')->where('UserID','=',1)->get()->pluck('ID');
在这里您可以阅读更多有关在查询中使用 pluck 时发生这种情况的原因 Pluck together with first using Query builder
更新: 我忘记了 DB::table returns 数组,所以:
$items = DB::table('table1')->where('UserID','=',1)->get();
$itemsById = array_pluck($items, 'ID');
使用 first 而不是 get 作为获取 return 数组。
$itemid = DB::table('table1')->where('UserID','=',1)->first()->pluck( 'ID');