PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 1, 2022

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

 February 01, 2022     eloquent, laravel, laravel-5, laravel-query-builder     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing