1. Go to this page and download the library: Download laravolt/suitable 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/ */
{!! Suitable::source(User::all())
->columns([
[
'header' => 'Roles',
'raw' => function($data){
// do anything here and don't forget to return String
return $data->roles->implode('name', ', '); // output: "role1, role2, role3"
}
],
])
->render() !!}`
{!! Suitable::source(User::all())
->columns([
new \App\Columns\StatusColumn('Status'),
])
->render() !!}
namespace Laravolt\Suitable\Columns;
interface ColumnInterface
{
public function header();
public function headerAttributes();
public function cell($cell, $collection, $loop);
public function cellAttributes($cell);
public function sortable();
}
namespace App\Columns;
use Laravolt\Suitable\Columns\ColumnInterface;
class StatusColumn implements ColumnInterface
{
protected $header;
public function __construct($header)
{
$this->header = $header;
}
public function header()
{
return $this->header;
}
public function cell($cell, $collection, $loop)
{
return sprintf("<div class='ui label'>%s</div>", $cell->status);
}
public function headerAttributes()
{
return [];
}
public function cellAttributes($cell)
{
return [];
}
}
namespace App\Http\Controllers;
use App\User;
use Illuminate\Routing\Controller;
use Laravolt\Suitable\Plugins\Pdf;
use Laravolt\Suitable\Plugins\Spreadsheet;
use Laravolt\Suitable\Tables\BasicTable;
class SuitableController extends Controller
{
public function __invoke()
{
$table = (new BasicTable(new User()));
return $table->view('etalase::example.suitable');
}
}
namespace App\Table;
use Laravolt\Suitable\Columns\Date;
use Laravolt\Suitable\Columns\DateTime;
use Laravolt\Suitable\Columns\Id;
use Laravolt\Suitable\Columns\Numbering;
use Laravolt\Suitable\Columns\Text;
use Laravolt\Suitable\TableView;
class UserTable extends TableView
{
protected function columns()
{
return [
Numbering::make('No'),
Id::make('id'),
Text::make('name'),
Text::make('email'),
Date::make('created_at'),
DateTime::make('updated_at'),
];
}
}
namespace Laravolt\Etalase\Http\Controllers;
use App\User;
use Illuminate\Routing\Controller;
use App\Table\UserTable;
use Laravolt\Suitable\Plugins\Pdf;
use Laravolt\Suitable\Plugins\Spreadsheet;
class SuitableController extends Controller
{
public function __invoke()
{
$users = User::autoSort()->paginate(5);
$userTable = new UserTable($users);
$table = $userTable
->plugins([
(new Pdf('users.pdf')),
(new Spreadsheet('users.xls')),
]);
return $table->view('etalase::example.suitable');
}
}