1. Go to this page and download the library: Download devig/laravel-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/ */
$rows = User::get(); // Get all users from the database
$table = Table::create($rows); // Generate a Table based on these "rows"
return view('users.index', ['table' => $table]);
{!! $table->render() !!}
use Gbrock\Table\Traits\Sortable;
class User extends Model {
use Sortable;
/**
* The attributes which may be used for sorting dynamically.
*
* @var array
*/
protected $sortable = ['username', 'email', 'created_at'];
$rows = User::sorted()->get(); // Get all users from the database, but listen to the user Request and sort accordingly
$rows = User::sorted()->paginate(); // Get all users from the database, sort, and paginate
$table = Table::create($rows, ['username', 'created_at']); // Generate a Table based on these "rows"
// We pass in the field, label, and a callback accepting the model data of the row it's currently rendering
$table->addColumn('created_at', 'Added', function($model) {
return $model->created_at->diffForHumans();
});
protected function getRenderedCreatedAtAttribute()
{
// We access the following diff string with "$model->rendered_created_at"
return $this->created_at->diffForHumans();
}
$table->setView('users.table');
php artisan vendor:publish
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.