From d2fecec24a2551cafb9258b75dab1d83c8899ea8 Mon Sep 17 00:00:00 2001 From: Julio Motol Date: Fri, 11 Dec 2020 10:49:33 +0800 Subject: [PATCH] Add current breadcrumbs caching Signed-off-by: Julio Motol --- src/Manager.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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); } /**