Issue
Hello I am building an auction system. where for now i will consider two tables. Auction table and Bidding table. I want to build eloquent query so that I can get maximum amount and all other amounts separately because I will transfer maximum amount to seller and other amount to refund their users.
I don't know from where I should start.
Auction table migration
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();
});
}
Bidding table migration
public function up()
{
Schema::create('biddings', function (Blueprint $table) {
$table->bigIncrements('id');
$table->Integer('userID');
$table->integer('auctionID');
$table->bigInteger('amount');
$table->timestamps();
});
}
I want to get maximum amount and other amounts separately.
Solution
Since the amount is just an integer, retrieve all amounts and pop the maximum out of the collection
$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
Answered By - Salim Djerbouh
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.