Last active
October 1, 2019 04:19
-
-
Save daemswibowo/18993b9345bda04a0999cfa17e5ef770 to your computer and use it in GitHub Desktop.
Group Count Invoices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class Invoice extends Model | |
{ | |
public function bulan () | |
{ | |
return $this->hasMany('App\Invoice', 'bill_year','bill_year'); | |
} | |
public function scopeWithBulan ($q, $status = 0) | |
{ | |
return $q->whereStatus($status)->with(['bulan' => function ($q) use ($status) { | |
$q->select('bill_month','bill_year', \DB::raw('count(id) as jumlah'))->groupBy('bill_year','bill_month')->whereStatus($status); | |
}]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\Invoice; | |
class InvoiceController extends Controller | |
{ | |
public function index () | |
{ | |
$invoices_true = Invoice::select('bill_year', \DB::raw('count(id) as jumlah'))->groupBy('bill_year')->withBulan(1)->get(); | |
$invoices_false = Invoice::select('bill_year', \DB::raw('count(id) as jumlah'))->groupBy('bill_year')->withBulan(0)->get(); | |
$items = ["TRUE" => $invoices_true, "FALSE" => $invoices_false]; | |
return $items; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment