雄弁にキーワード「として」を含むLaravelの変換生のクエリ

マジッドAlaeinia:

私は、この生のクエリを持っています:

SELECT business_id, count(*) as how_many from dbname.gateway_transactions WHERE DATE(created_at) = '2020-02-02' group by business_id order by how_many desc limit 5

そして、これは結果は次のとおりです。

ここでは、画像の説明を入力します。

私は配列として、このクエリ(画像の内容)の結果を持っていると思います。これどうやってするの?

私はこれを使用しています:

$a = GatewayTransaction::selectRaw("SELECT business_id, count(*) as how_many from dbname.gateway_transactions WHERE DATE(created_at) = '2020-02-02' group by business_id order by how_many desc limit 5");

しかし、私は必要なものを取得することができません。私は上記の画像のように、このような配列が必要になります。

[
51  => 725,
176 => 405,
229 => 264,
98  => 109,
136 => 92
]
Tsakhog:

あなたはこのように雄弁ビルダーを使用する必要があります。

$a = GatewayTransaction::selectRaw('business_id, count(*) as how_many')
                       ->whereDate('created_at', '2020-02-02')
                       ->groupBy('business_id')
                       ->orderBy('how_many', 'desc')
                       ->take(5)
                       ->get();

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=298983&siteId=1