|
/** |
|
* Laravel 4.1 HTML Macro to generate breadcrumbs! |
|
* |
|
* Use it to generate breadcrumbs that compatible with Bootstrap 3. |
|
* |
|
* To use it you need to pass value through $arrayLinks with array that contains |
|
* named keys and it value. Key would be the label of breadcrumbs and value |
|
* would be the link. If we don't pass the named key then it would be label without |
|
* link attached. |
|
* |
|
* To customise home you may use "$homeLinks" with array that contains 'link' and |
|
* 'label' as keys with it corresponding value. |
|
* |
|
* Example: |
|
* |
|
* $arrayLinks = array( |
|
* 'Post Index'=>route('post-index'), // breadcrumb element to index |
|
* 'Editing ' . $post->title // last elements of breadcrumbs |
|
* ); |
|
* |
|
* $homeLinks = array( |
|
* 'label' => 'Control Panel', // change default index |
|
* 'link' => route('control-panel') // and it link |
|
* ); |
|
* |
|
* {{ HTML::breadcrumbs( $arrayLinks, $homeLinks ) }} |
|
*/ |
|
|
|
HTML::macro('breadcrumbs', function($arrayLinks, $homeLinks=null){ |
|
$link = array(); |
|
// first generate for home ... |
|
$theHome = array('link'=>'/', 'label'=>'Home'); |
|
if($homeLinks!==null) { |
|
if(is_array($homeLinks)) { |
|
$theHome['link'] = !isset($homeLinks['link'])?:$homeLinks['link']; |
|
$theHome['label'] = !isset($homeLinks['label'])?:$homeLinks['label']; |
|
} else { |
|
$theHome['link'] = $homeLinks; |
|
} |
|
} |
|
$link[] = sprintf('<li><a href="%s">%s</a></li>', $theHome['link'], $theHome['label']); |
|
// second lets check all links ... |
|
foreach ($arrayLinks as $key => $value) { |
|
// the key would be label and value would be the link! |
|
if(is_numeric($key)) { |
|
// then it must be label without link ... |
|
$link[] = sprintf('<li>%s</li>', |
|
$value); |
|
} else { |
|
$link[] = sprintf('<li><a href="%s">%s</a></li>', |
|
$value, $key); |
|
} |
|
} |
|
return '<ol class="breadcrumb">' |
|
.implode("", $link) |
|
.'</ol>'; |
|
}); |