Created
April 20, 2014 21:20
-
-
Save cgiovanii/11125561 to your computer and use it in GitHub Desktop.
Bootstrap 3 Table Editable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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