Skip to content

Instantly share code, notes, and snippets.

@kdocki
Last active January 3, 2016 04:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdocki/ccdfacd391b143dbb7f7 to your computer and use it in GitHub Desktop.
Save kdocki/ccdfacd391b143dbb7f7 to your computer and use it in GitHub Desktop.
<?php
/**
* HTML::show_message_when('first_name', $errors)
*/
HTML::macro('show_message_when', function show_message_when($name, $errors, $attributes = array())
{
$attributes_string = "";
$content_string = "";
$attributes['class'] = isset($attributes['class']) ?: "";
$attributes['class'] .= " $name";
if ($errors->has($name))
{
$attributes['class'] .= " alert";
$attributes['class'] .= " alert-danger";
$content_string = $errors->first($name);
}
foreach ($attributes as $key => $value) {
$attributes_string = " $key = \"" . $value . "\"";
}
return "<div $attributes_string>$content_string</div>";
});
/**
* HTML::foreach('user', 'user.itemview', $users)
*/
HTML::macro('foreach', function($name, $view, $items)
{
var html = "";
foreach ($items as $item)
{
html .= View::make($view, [$name => $item]);
}
return html;
});
/**
* HTML::not_found($users, 'No users found!')
*/
HTML::macro('not_found', function($items, $message = 'None found!')
{
return '<div class="empty row">' . $message . '</div>';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment