1. Go to this page and download the library: Download hasanhawary/report-builder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Reports;
use HasanHawary\ReportBuilder\BaseReport;
use Illuminate\Support\Facades\DB;
class UserReport extends BaseReport
{
public string $table = 'users';
/**
* Data for summary cards
*/
public function getStats(): array
{
$data = [
'total' => DB::table($this->table)->count(),
'active' => DB::table($this->table)->where('active', 1)->count(),
];
return $this->cardResponse($data);
}
/**
* Data for a spline chart
*/
public function getRegisteredByDate(): array
{
$data = DB::table($this->table)
->selectRaw("DATE_FORMAT(created_at, '%Y-%m-%d') as date, COUNT(*) as count")
->groupBy('date')
->get();
return $this->chartResponse('date', $data);
}
/**
* Data for a table
*/
public function getUserList(): array
{
$data = DB::table($this->table)
->select('id', 'name', 'email', 'created_at')
->limit(10)
->get();
return $this->chartResponse('id', $data); // chartResponse handles 'table' type automatically
}
}
use HasanHawary\ReportBuilder\ReportBuilder;
public function index()
{
return (new ReportBuilder([
'page' => 'user',
'start' => '2024-01-01',
'end' => '2024-12-31',
]))->response();
}