Skip to content

Commit

Permalink
Clear collection on new call
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Dec 11, 2020
1 parent d2fecec commit c5a6baa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
13 changes: 1 addition & 12 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ class Manager
*/
protected $generator;

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

/**
* Create the instance of the manager.
*
Expand Down Expand Up @@ -63,17 +56,13 @@ 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->cachedCurrentBreadcrumbs = $this->generate($name, $parameters);
return $this->generate($name, $parameters);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Trail.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function register(string $name, Closure $definition)
*/
public function generate(string $route, array $parameters = []): Collection
{
$this->breadcrumbs = $this->breadcrumbs->whenNotEmpty(function () {
return new Collection();
});

$parameters = $this->getRouteByNameParameters($route, $parameters);

if ($route && $this->registrar->has($route)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/BreadcrumbsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ public function testBreadcrumbsTimesOne(): void
$this->assertEquals('1', $count);
}


public function testBreadcrumbsIdempotency(): void
{
Route::get('/breadcrumbs-home', function () {
Breadcrumbs::current();
Breadcrumbs::generate('breadcrumbs-home');

return Breadcrumbs::current()->toJson();
})->name('breadcrumbs-home');
Expand Down

0 comments on commit c5a6baa

Please sign in to comment.