Skip to content

Commit

Permalink
Add support for chained functions based off of legacy PR:
Browse files Browse the repository at this point in the history
d13r/laravel-breadcrumbs#210

(Original PR repo was deleted, so code had to be manually copy-pasted)

Closes #25
  • Loading branch information
shengslogar committed May 23, 2021
1 parent 6de35c3 commit 0a1334f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ protected function call(string $name, array $params): void
*
* @param string $name The name of the parent page.
* @param array ...$params The parameters to pass to the closure.
* @return self
* @throws InvalidBreadcrumbException
*/
public function parent(string $name, ...$params): void
public function parent(string $name, ...$params): self
{
$this->call($name, $params);

return $this;
}

/**
Expand All @@ -86,9 +89,12 @@ public function parent(string $name, ...$params): void
* @param string $title The title of the page.
* @param string|null $url The URL of the page.
* @param array $data Optional associative array of additional data to pass to the view.
* @return self
*/
public function push(string $title, ?string $url = null, array $data = []): void
public function push(string $title, ?string $url = null, array $data = []): self
{
$this->breadcrumbs->push((object)array_merge($data, compact('title', 'url')));

return $this;
}
}
20 changes: 20 additions & 0 deletions tests/AdvancedUsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,24 @@ public function testClearCurrentRoute()

Breadcrumbs::render();
}

public function testBreadcrumbsSupportForArrowFunctions()
{
Route::name('home')->get('/', function () { });
Route::name('blog.index')->get('/blog', function () { });

Breadcrumbs::for('home', function ($trail) {
$trail->push('Some Data')
->push('Another Set');
});

Breadcrumbs::for('blog.index', function ($trail) {
$trail->parent('home')
->push('Yet Another');
});

$breadcrumbs = Breadcrumbs::generate('blog.index');

$this->assertCount(3, $breadcrumbs);
}
}

0 comments on commit 0a1334f

Please sign in to comment.