Skip to content

Instantly share code, notes, and snippets.

@robotamer robotamer/msg.php
Created Jun 27, 2012

What would you like to do?
A messanger for the Laravel Framework
class Msg {
public static $msgss = array();
* Add a message to the message array (adds to the user's session)
* @param string $type You can have several types of messages, these are class names for Bootstrap's messaging classes, usually, info, error, success, warning
* @param string $message The message you want to add to the list
public static function add($type = 'info', $message = FALSE){
if(!$message) return FALSE;
foreach($message as $msg){
static::$msgss[$type][] = $msg;
static::$msgss[$type][] = $message;
Session::flash('messages', static::$msgss);
* Pull back those messages from the session
* @return array
public static function get(){
return (Session::has('messages')) ? Session::get('messages') : FALSE;
* Gets all the messages from the session and formats them accordingly for Twitter bootstrap.
* @return string
public static function getHtml(){
$output = FALSE;
if (Session::has('messages')){
$messages = Session::get('messages');
foreach($messages as $type => $msgs){
if(is_integer($type)) $type = 'error';
$output .= '<div class="alert alert-'.$type.'"><a class="close" data-dismiss="alert">×</a>';
foreach($msgs as $msg) $output .= '<p>'.$msg.'</p>';
$output .= '<p>'.$msgs.'</p>';
$output .= '</div>';
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.