Query\Builder::keyBy 不存在 (Laravel)

Query\Builder::keyBy does not exist (Laravel)

我已经创建了一个命令,我正在尝试查询我的数据库并按一个键对我的结果进行分组,但我一直收到此错误:

In Builder.php line 2512:

  Method Illuminate\Database\Query\Builder::keyBy does not exist. 

Laravel 版本为 5.6.4

命令代码:

    <?php

namespace App\Console\Commands;

use App\User;
use Illuminate\Console\Command;

class TwitchPointScanner extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:twitchPointScanner';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Twitch Point Scanner';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $usersDistributors = User::where('point_distributor', 1)
            ->inRandomOrder()
            ->get();
        $usersTwitchVerified = User::where('point_distributor', 0)
            ->whereNotNull('twitch_username')
            ->keyBy('twitch_username')
            ->get();

        $this->line('Distributors ---');
        foreach($usersDistributors as $user) {
            $this->line($user->id . ': '.$user->twitch_username);
        }

        $this->line('Point gainers ---');
        foreach($usersTwitchVerified as $user) {
            $this->line($user->id . ': '.$user->twitch_username);
        }

    }
}

keyBy是采集方式,所以需要先获取数据:

$usersTwitchVerified = User::where('point_distributor', 0)
    ->whereNotNull('twitch_username')
    ->get()
    ->keyBy('twitch_username');