Skip to content

Instantly share code, notes, and snippets.

@permatis
Last active March 10, 2016 03:30
Show Gist options
  • Save permatis/3ec04c5be77049f24250 to your computer and use it in GitHub Desktop.
Save permatis/3ec04c5be77049f24250 to your computer and use it in GitHub Desktop.
It is helper for easy and simple make breadcrumbs in laravel.
<?php
/**
* Create breadcrumb to easy and simple.
*
* @param string $homebase Title for home page or dashboard page
* @param string $separat Other symbols that are used for separatian, and default null
* @return $breadcrumb Make breadcrumb combine into one]
*/
function breadcrumb($homebase = 'Home', $separate = '')
{
$page = explode('/', request()->path());
$homepage = array_shift($page);
$lastpage = array_keys($page);
$breadcrumb = ["<li>".link_to($homepage, $homebase)."</li>"];
foreach ($page as $key => $value) {
if($key != end($lastpage)) {
if(!is_numeric($value))
$breadcrumb[] = "<li>".link_to($homepage.'/'.$value, ucwords($value))."</li>";
} else {
$breadcrumb[] = "<li class='active'>".ucwords($value)."</li>";
}
}
return implode($separate, $breadcrumb);
}

###How to use ### I referenced from stackoverflow This helper required package laravelcollective/html.

For review : <?php breadcrumb(); ?> //php {!! breadcrumb('Dashboard', '>') !!} //laravel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment