PHP code example of lloricode / laravel-html-table
1. Go to this page and download the library: Download lloricode/laravel-html-table 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/ */
lloricode / laravel-html-table example snippets
$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
)
!!}