https://github.com/lloricode/laravel-html-table
Generate Html Table with data from Array/Collection.
https://github.com/lloricode/laravel-html-table
hacktoberfest html laravel table
Last synced: 7 months ago
JSON representation
Generate Html Table with data from Array/Collection.
- Host: GitHub
- URL: https://github.com/lloricode/laravel-html-table
- Owner: lloricode
- License: mit
- Created: 2017-07-19T08:44:29.000Z (about 9 years ago)
- Default Branch: develop
- Last Pushed: 2025-08-12T07:09:44.000Z (12 months ago)
- Last Synced: 2025-09-15T04:19:34.339Z (10 months ago)
- Topics: hacktoberfest, html, laravel, table
- Language: PHP
- Homepage:
- Size: 197 KB
- Stars: 15
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Laravel HTML Table
[](https://packagist.org/packages/lloricode/laravel-html-table)
[](https://github.com/lloricode/laravel-html-table/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/lloricode/laravel-html-table/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[](https://packagist.org/packages/lloricode/laravel-html-table)
[](https://codecov.io/gh/lloricode/laravel-html-table)
Generate Html Table with data from array/object.
## Installation
You can install the package via composer:
```bash
composer require lloricode/laravel-html-table
```
## Usage
### Sample in view
```php
$headers = ['col1', 'col2'];
$data = [
[
'Lloric', 'Garcia',
],
[
'Foo', 'Bar',
],
[
'Foo1', 'bar11',
],
[
'tst', 'tesss',
],
];
$attributes = 'class="table"';
// Or
$attributes = ['myclass' => 'test_val'];
{!! Table::generate($headers, $data) !!}
{!! Table::generate($headers, $data, $attributes) !!}
// Model way
{!!
Table::generateModel(
['Id', 'Name', 'Email'], // Column for table
'App\User' // Model
,['id', 'name', 'email'], // Fields from model
0, // Pagination Limit, if 0 all will show
'border="1"' // Attributes sample js/css
)
!!}
{{ Table::links() }} // Generate this when limit is not 0
// then you can add a links
{!!
Table::optionLinks('my.route.name')
->modelResult(function($query){ // you can add filter if you are using model generate
$query->where('user_id', auth()->user()->id);
return $query;
})
->generateModel(
['Id', 'Name', 'Email'], // Column for table
'App\User' // Model
,['id', 'name', 'email'], // Fields from model
5, // Pagination Limit, if 0 all will show
'border="1"' // Attributes sample js/css
)
!!}
// you can specify more args
// 1st route name, 2nd header label, and 3rd is the every row label
{!!
Table::optionLinks('my.route.name', 'my option', 'view')
->generateModel(
['Id', 'Name', 'Email'], // Column for table
'App\User' // Model
,['id', 'name', 'email'], // Fields from model
5, // Pagination Limit, if 0 all will show
'border="1"' // Attributes sample js/css
)
!!}
```
### This is all default values html tags
```php
$attributes = [
// Main Table
'table' => '',
'table_end' => '',
// Head
'head' => '',
'head_end' => '',
'head_row' => '',
'head_row_end' => '',
'head_cell' => '',
'head_cell_end' => '',
// Data body
'body' => '',
'body_end' => '',
'body_row' => '',
'body_row_end' => '',
'body_cell' => '',
'body_cell_end' => '',
// Alternative
'alt_body_row' => '',
'alt_body_row_end' => '',
'alt_body_cell' => '',
'alt_body_cell_end' => '',
];
{!! Table::generate($headers, $data, $attributes) !!}
```
### Sample Output
```php
col1col2LloricGarciaFooBarFoo1bar11tsttesss
```
### Adding attributes in cell data
```php
$header = ['Date', 'Description', 'Amount'];
$datas = [
[
['data' => '1', 'scope' => 'row'],
'Mark',
'Otto',
],
[
['data' => '2', 'scope' => 'row'],
'foo',
'varr',
],
];
{!! Table::generate($header, $datas, ['class'=>'table']) !!}
Date
Description
Amount
1
Mark
Otto
2
foo
varr
```
## Testing
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits
- [Lloric Mayuga Garcia](https://github.com/lloricode)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.