如何在 laravel 中分别获得最大金额和所有其他金额?

How to get maximum amount and all other amounts separately in laravel?

您好,我正在构建一个拍卖系统。现在我将考虑两个 table。拍卖 table 和投标 table。我想构建 eloquent 查询,以便我可以分别获得最大金额和所有其他金额,因为我会将最大金额转移给卖家,其他金额会退还给他们的用户。

我不知道应该从哪里开始。

拍卖table迁移

   public function up()
    {
        Schema::create('auctions', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->Integer('productID');
            $table->Integer('price');
            $table->Integer('quantity');
            $table->dateTime('endTimeDate');
            $table->dateTime('startTimeDate');
            $table->timestamps();
        });
    }

投标table迁移

  public function up()
    {
        Schema::create('biddings', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->Integer('userID');
            $table->integer('auctionID');
            $table->bigInteger('amount');
            $table->timestamps();
        });
    }

我想分别获得最高金额和其他金额。

由于金额只是一个整数,检索所有金额并从集合中弹出最大值

$other_amounts = \DB::table('biddings')->select('amount')->orderBy('amount')->get();
$maximum = $other_amounts->pop(); // this will get the maximum
echo $other_amounts; // Here are all the amounts except the maximum