Skip to content

Instantly share code, notes, and snippets.

@ahmadshah
Created May 18, 2014 20:12
Show Gist options
  • Save ahmadshah/5d77a91c21ac98ded2fa to your computer and use it in GitHub Desktop.
Save ahmadshah/5d77a91c21ac98ded2fa to your computer and use it in GitHub Desktop.
Orchestra\HTML Table
<?php namespace Eisai\Foundation\Presenter;
use Orchestra\Support\Str;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\HTML;
use Orchestra\Support\Facades\Form;
use Orchestra\Support\Facades\Table;
use Orchestra\Html\Table\TableBuilder;
use Orchestra\Foundation\Presenter\AbstractablePresenter;
class User extends AbstractablePresenter {
public function table($model)
{
return Table::of('eisai.foundation: table', function ($table) use ($model) {
$table->with($model, true);
$table->layout('orchestra/foundation::components.table');
$table->column('fullname', function ($column) {
$column->label('Name');
$column->attributes(function ($row) {
return ['width' => '15%'];
});
});
$table->column('email', function ($column) {
$column->label('email');
$column->attributes(function ($row) {
return ['width' => '10%'];
});
});
$table->column('role', function ($column) {
$column->label('Role');
$column->attributes(function ($row) {
return ['width' => '10%'];
});
$column->value(function ($row) {
$roles = $row->roles()->lists('name');
return implode($roles, ', ');
});
});
$table->column('status', function ($column) {
$column->label('Status');
$column->attributes(function ($row) {
return ['width' => '8%'];
});
$column->value(function ($row) {
return (bool) $row->status ? 'Active' : 'Not active';
});
});
$table->column('last_login_at', function ($column) {
$column->label('Last Logged In');
$column->attributes(function ($row) {
return ['width' => '10%'];
});
$column->value(function ($row) {
return $row->last_login_at;
});
});
$table->column('action', function ($column) {
$column->label('Actions');
$column->attributes(function ($row) {
return ['width' => '5%'];
});
$column->value(function ($row) {
$btn = [];
$btn[] = HTML::link(
'#glossary-view',
HTML::raw('<i class="fa fa-search"></i>'),
[
'class' => 'btn btn-xs btn-primary glossary-view-trigger',
'data-term' => $row->term,
'data-definition' => $row->definition
]
);
$btn[] = HTML::link(
handles("orchestra::users/{$row->id}/edit"),
HTML::raw('<i class="fa fa-edit"></i>'),
[
'class' => 'btn btn-xs btn-success'
]
);
if (Auth::user()->isAny(['Superadmin', 'Administrator'])) {
$btn[] = HTML::link(
handles("orchestra::users/destroy/{$row->id}"),
HTML::raw('<i class="fa fa-trash-o"></i>'),
[
'class' => 'btn btn-xs btn-danger'
]
);
}
return implode(' ', $btn);
});
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment