CodeIgniter Laravel PHP Example Javascript jQuery MORE

How to show total amount month and year wise Laravel

In this example we will discuss about how to show total amount month and year wise from database table using CodeIgniter framework PHP.

For show total amount month and year wise we uses 3 file here

  1. total_amount.blade.php
  2. TotalAmountController.php
  3. web.php


<!DOCTYPE html>
<title>Total Amount Calculation</title>
<table border = 1>
<td> Year</td>
<td> Month</td>
<td> Amount</td>
@foreach ($users as $user)
<?php $monthNum = $user->month;
$dateObj = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F');?>
<td>{{ $user->year}}</td>
<td>{{ $monthName }}</td>
<td>{{ $user->total_amount }}</td>


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class TotalAmountController extends Controller {
public function store(){
$users = DB::select('select year(date) as year, month(date) as month, sum(paid) as total_amount from amount_table group by year(date), month(date)');
return view('total_amount',['users'=>$users]);


/* |--------------------------------------------------------------------------
| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
//delete data

Now run the program on your browser with the below URL:

This is my database table

After run the code i get the output


Year Month Total Amount
2016 August 150
2017 August 150
2017 September 300

Thank you !