mercredi 16 décembre 2020

How to sum column with groupBy query in laravel?

I have multiple record in database with same product name . Now I want that all the record should come once but their quantity column should be sum up. I want to sum quantity on monthly and yearly basis.

It will basically display summary of product on yearly and monthly basis.

Order Table migration

 public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->string('amzid',500)->nullable();
            $table->string('samid',500)->nullable();
            $table->string('quantity',500)->nullable();
            $table->string('samq',500)->nullable();
            $table->text('samp',5000)->nullable();
            $table->text('same')->nullable();
            $table->string('pname',7000)->nullable();
            $table->text('note')->nullable();
            $table->timestamps();
        });
    }

This is dummy query i dont know how to start

Order::groupBy('pname')->sum('quantity')->lastthirtyDay() ??



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire