Skip to content
This repository was archived by the owner on Oct 18, 2020. It is now read-only.

Added support arrow function #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions classes/BreadcrumbsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,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.
* @throws InvalidBreadcrumbException
*
* @return BreadcrumbsGenerator
*/
public function parent(string $name, ...$params): void
public function parent(string $name, ...$params): BreadcrumbsGenerator
{
$this->call($name, $params);

return $this;
}

/**
Expand All @@ -90,9 +94,13 @@ 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 BreadcrumbsGenerator
*/
public function push(string $title, string $url = null, array $data = []): void
public function push(string $title, string $url = null, array $data = []): BreadcrumbsGenerator
{
$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 @@ -271,4 +271,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);
}
}