Skip to content

Instantly share code, notes, and snippets.

@cgiovanii
Created April 20, 2014 21:20
Show Gist options
  • Save cgiovanii/11125561 to your computer and use it in GitHub Desktop.
Save cgiovanii/11125561 to your computer and use it in GitHub Desktop.
Bootstrap 3 Table Editable
// Macro
HTML::macro('table', function($fields = array(), $data = array(), $resource, $showEdit = true, $showDelete = true, $showView = true){
$table = '<table class="table table-bordered">';
$table .='<tr>';
if ($showEdit || $showDelete || $showView )
$table .= '<th></th>';
foreach ($fields as $field)
{
$table .= '<th>' . Str::title($field) . '</th>';
}
$table .= '</tr>';
foreach ( $data as $d )
{
$table .= '<tr>';
if ($showEdit || $showDelete || $showView )
{
$table .= '<td>';
if ($showEdit)
$table .= '<a href="' . $resource . '/' . $d->id . '/edit" class="btn btn-sm btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a> ';
if ($showView)
$table .= '<a href="' . $resource . '/' . $d->id . '" class="btn btn-sm btn-primary"><i class="glyphicon glyphicon-eye-open"></i> View</a> ';
if ($showDelete)
$table .= '<a href="' . $resource . '/' . $d->id . '/delete" class="btn btn-sm btn-danger"><i class="glyphicon glyphicon-remove"></i> Delete</a> ';
$table .= '</td>';
}
foreach($fields as $key) {
$table .= '<td>' . $d->$key . '</td>';
}
$table .= '</tr>';
}
$table .= '</table>';
return $table;
});
// Example of call
{{ HTML::table(array('name', 'emai', 'birthday'), User::all(), 'users', false, false) }}
- See more at: http://laravelsnippets.com/snippets/bootstrap-3-table-macro#sthash.XhSRhGRu.dpuf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment