PHP code example of mokhosh / laravel-reporter
1. Go to this page and download the library: Download mokhosh/laravel-reporter 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/ */
mokhosh / laravel-reporter example snippets
use Mokhosh\Reporter\Reporter;
$users = User::query();
return Reporter::report($users)->pdf(); // view in browser, aka inline
return Reporter::report($users)->download()->pdf(); // download, aka attachment
return Reporter::report($users)->excel();
$filter = [
'id',
'name',
'email',
'created_at',
];
return Reporter::report($users, $filter)->pdf();
$filter = [
'id' => 'ID',
'email' => '@',
'created_at' => 'Joined',
];
$filter = [
'created_at' => fn($date) => $date->format('Y-m'),
];
$filter = [
'id' => [
'class' => 'font-bold text-gray-600 bg-gray-50'
],
];
$filter = [
'id' => 'ID',
'name',
'email' => [
'transform' => fn($email) => strtoupper($email),
'class' => 'text-green-700 bg-green-100',
],
'created_at' => fn($date) => $date->format('Y-m'),
'updated_at' => [
'title' => 'Last Seen',
'class' => 'text-red-400',
],
];
$filter = [
'amount' => fn($amount, $model) => $model->currency . $amount,
];
$filter = [
'madeup_name' => fn($_, $model) => $model->amount * $model->discount,
];
$title = 'Users Report';
$meta = [
'Admin' => 'Mo Khosh',
];
return Reporter::report($query, $columns, $title, $meta, footer: true)->pdf();
return Reporter::report($query, $columns, footer: true)->pdf();
return Reporter::report($query, $columns, logo: 'https://address-to-logo.com')->pdf();
$filter = [
'id' => 'ID',
'email' => [
'class' => 'text-green-700 bg-green-100',
'header-class' => 'text-green-100 bg-green-700',
],
];
$filter = [
'created_at' => [
'conditional-classes' => [
[
'class' => 'text-red-600',
'condition' => fn($date) => $date->gt(now()->subWeek()),
],
[
'class' => 'text-green-600',
'condition' => fn($date) => $date->lt(now()->subYear()),
],
],
],
];