Features:
- Easily create tables/data reports/exports
- Support multiple formats (CSV, HTML)
- Usable for data export with custom business logic
You can install the package via composer:
composer require brilliant-code/table
Imagine you need to build this table:
+---------+----------------+----------+
| Count | | 3 |
+---------+----------------+----------+
| John | [email protected] | pwdjohn |
| Mike | [email protected] | mikepwd |
| Another | [email protected] | password |
+---------+----------------+----------+
Write the following Table-class:
final class UsersTable extends Table
{
/** @var User[] */
private $users;
public function query(): array
{
return [
'users' => User::withCount()->get(),
];
}
/**
* Allowed sources to display
*/
public function sources(): array
{
return [CsvSource::class, HtmlSource::class];
}
public function handle(Source $source)
{
$users = $this->users;
$source->addRow(['Count', '', $users->count]);
foreach ($users as $user){
$source->addRow([$user->name, $user->email, $user->password]);
}
return $source;
}
}
// And Usage:
echo (new UsersTable)->display(HtmlSource::class);
composer test
Please see CHANGELOG for more information on what has changed recently.
Pull requests are welcome. Thank you :)
The MIT License (MIT). Please see License File for more information.