cgiovanii
4/20/2014 - 9:20 PM

Bootstrap 3 Table Editable

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