Skip to content

[WIP] Easily create tables. Support multiple formats (CSV, HTML). Usable for data export with custom business logic

License

Notifications You must be signed in to change notification settings

brilliant-code/table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tables

Latest Version on Packagist Build Status Quality Score Total Downloads

Features:

  • Easily create tables/data reports/exports
  • Support multiple formats (CSV, HTML)
  • Usable for data export with custom business logic

Installation

You can install the package via composer:

composer require brilliant-code/table

Usage

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);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Pull requests are welcome. Thank you :)

Credits

License

The MIT License (MIT). Please see License File for more information.

About

[WIP] Easily create tables. Support multiple formats (CSV, HTML). Usable for data export with custom business logic

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages