您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-查詢構造器-獲取一列(指定id字段的值作爲索引)
发布时间:2022-02-01 20:48:35编辑:雪饮阅读()
這種需求一般比較少,但是也是存在的
控制器中的實現:
public function index(Request $request)
{
$usernames = Db::table('ecms_news')->pluck('username', 'id');
foreach ($usernames as $id => $username) {
echo "index:".$id." username:".$username."\r\n";
if($id>100){
break;
}
}
return response("ok");
}
實例運行后並訪問:
[root@localhost webman]# /usr/local/php734/bin/php -c /usr/local/php734/lib/php.ini start.php start
Workerman[start.php] start in DEBUG mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.26 PHP version:7.3.4
------------------------------------------ WORKERS ------------------------------------------
proto user worker listen processes status
tcp root webman http://0.0.0.0:8787 4 [OK]
tcp root monitor none 1 [OK]
---------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
訪問了全局中間件!
index:86 username:雪饮
index:87 username:雪饮
index:90 username:雪饮
index:91 username:雪饮
index:92 username:雪饮
index:94 username:雪饮
index:95 username:雪饮
index:96 username:雪饮
index:99 username:雪饮
index:103 username:雪饮
关键字词:webman,查詢構造器,獲取一列,指定id字段的值作爲索引