Laravel allowing us to extend the HTML facade with additional functionality. we use the HTML::macro() method to extend the HTML facade with our own methods.So here is the Twitter Bootstrap alert macro.
Place the below macro code into your app/start/global.php file to register it.
HTML::macro('alert', function($type, $message, $head = null,$noHead = false) { switch ($type) { case 'success': //green color $head = $head ? $head : 'Success'; break; case 'danger': //red color $head = $head ? $head : 'Error'; break; case 'warning': //yellow color $head = $head ? $head : 'Warning'; break; case 'info': //blue color $head = $head ? $head : 'Info'; break; } return $noHead ? '' . $message . '':''. $head .': ' . $message . ''; });
How to use
Then place place this code in your blade template.
With Default head
{{ HTML::alert('success', 'your message') }}
// output: success your message
{{ HTML::alert('danger', 'your message') }}
// output : danger your message
{{ HTML::alert('warning', 'your message') }}
// output : warning your message
{{ HTML::alert('info', 'your message') }}
//output : info your message
With custom head
{{ HTML::alert('success', 'your message','Success message') }}
// output: Success message your message
{{ HTML::alert('danger', 'your message','Danger message') }}
// output : Danger message your message
{{ HTML::alert('warning', 'your message','Warning message') }}
// output : Warning message your message
{{ HTML::alert('info', 'your message','Info message') }}
//output : Info message your message
Without head
{{ HTML::alert('success', 'your message',null,true) }}
// output: your message
{{ HTML::alert('danger', 'your message',null,true) }}
// output : your message
{{ HTML::alert('warning', 'your message',null,true) }}
// output : your message
{{ HTML::alert('info', 'your message',null,true) }}
//output : your message
success your message
{{ HTML::alert('danger', 'your message') }}
// output : danger your message
{{ HTML::alert('warning', 'your message') }}
// output : warning your message
{{ HTML::alert('info', 'your message') }}
//output : info your message
{{ HTML::alert('success', 'your message','Success message') }} // output:Success message your message{{ HTML::alert('danger', 'your message','Danger message') }} // output :Danger message your message{{ HTML::alert('warning', 'your message','Warning message') }} // output :Warning message your message{{ HTML::alert('info', 'your message','Info message') }} //output :Info message your message
Without head
{{ HTML::alert('success', 'your message',null,true) }}
// output: your message
{{ HTML::alert('danger', 'your message',null,true) }}
// output : your message
{{ HTML::alert('warning', 'your message',null,true) }}
// output : your message
{{ HTML::alert('info', 'your message',null,true) }}
//output : your message
your message
{{ HTML::alert('danger', 'your message',null,true) }}
// output : your message
{{ HTML::alert('warning', 'your message',null,true) }}
// output : your message
{{ HTML::alert('info', 'your message',null,true) }}
//output : your message