diff --git a/src/Manager.php b/src/Manager.php index 90e1493..f341b5e 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -21,6 +21,13 @@ class Manager */ protected $generator; + /** + * The cached current breadcrumb trail. + * + * @var Collection + */ + protected $cachedCurrentBreadcrumbs; + /** * Create the instance of the manager. * @@ -56,13 +63,17 @@ public function for(string $route, Closure $definition) */ public function current($parameters = null): Collection { + if ($this->cachedCurrentBreadcrumbs) { + return $this->cachedCurrentBreadcrumbs; + } + $name = optional(Route::current())->getName(); if ($name === null) { return collect(); } - return $this->generate($name, $parameters); + return $this->cachedCurrentBreadcrumbs = $this->generate($name, $parameters); } /**