Skip to content

Commit

Permalink
Add current breadcrumbs caching
Browse files Browse the repository at this point in the history
Signed-off-by: Julio Motol <julio.motol89@gmail.com>
  • Loading branch information
juliomotol committed Dec 11, 2020
1 parent ba4b5d5 commit d2fecec
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class Manager
*/
protected $generator;

/**
* The cached current breadcrumb trail.
*
* @var Collection
*/
protected $cachedCurrentBreadcrumbs;

/**
* Create the instance of the manager.
*
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit d2fecec

Please sign in to comment.