An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# Laravel HTML Table

[![Latest Version on Packagist](https://img.shields.io/packagist/v/lloricode/laravel-html-table.svg?style=flat-square)](https://packagist.org/packages/lloricode/laravel-html-table)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/lloricode/laravel-html-table/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/lloricode/laravel-html-table/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/lloricode/laravel-html-table/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/lloricode/laravel-html-table/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/lloricode/laravel-html-table.svg?style=flat-square)](https://packagist.org/packages/lloricode/laravel-html-table)
[![codecov](https://codecov.io/gh/lloricode/laravel-html-table/branch/main/graph/badge.svg?token=gQRHSwYXAm)](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.