Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0] Add breadcrumbs to a route entry #1073

Closed
tabuna opened this issue Apr 16, 2020 · 2 comments
Closed

[8.0] Add breadcrumbs to a route entry #1073

tabuna opened this issue Apr 16, 2020 · 2 comments
Assignees

Comments

@tabuna
Copy link
Member

tabuna commented Apr 16, 2020

Is your feature request related to a problem? Please describe.
I am always a little upset when you need to find and change bread crumbs for several routes. Due to the fact that they are indifferent files and are not related to each other. Therefore, you must first open the file with the routes to see the name of the route, then open another and find a match in it.

// routes/web.php
Route::get('/')->name('home');
Route::get('/about')->name('about');
// routes/breadcrumbs.php
Breadcrumbs::for('home', function ($trail) {
    $trail->push('Home');
});

Breadcrumbs::for('about', function ($trail) {
    $trail->parent('home');
    $trail->push('About');
});

This is not a problem when there are few routes, but when there are many in your application and there are breadcrumbs for everyone, it starts to bother.

Describe the solution you'd like

My suggestion is very simple - combine the announcement of routes and breadcrumbs.

Route::get('/')->name('home')->breadcrumbs(function ($trail) {
    $trail->push('Home');
});

Route::get('/about')->name('about')->breadcrumbs(function ($trail) {
    $trail->parent('home');
    $trail->push('About');
});

As you can see, we have lost the duplicate required parameter name.

Describe alternatives you've considered
Wait until such functionality appears in the dependent package.
Or expect a similar solution in another package dwightwatson/breadcrumbs

Additional context
I added a breadcrumbs branch with this feature

@tabuna tabuna self-assigned this Apr 16, 2020
@tabuna tabuna changed the title Add breadcrumbs to a route entry [8.0] Add breadcrumbs to a route entry Apr 20, 2020
@tabuna
Copy link
Member Author

tabuna commented Apr 21, 2020

It seems that the author of the used package for breadcrumbs will no longer support and develop it. I think that we can accept its achievements and use them on our own.

For us, there is no need to fully reproduce all the functionality including various display themes, therefore I propose a minimal set:

// Checks if data for the current/transmitted route
Breadcrumbs::has();
Breadcrumbs::has('dashboard.index');

// Get collection for route
Breadcrumbs::get();

With usage examples:

@foreach (Breadcrumbs::get() as $crumbs)
    @if ($crumbs->url() && !$loop->last)
        <li class="breadcrumb-item">
            <a href="{{ $crumbs->url() }}">
                {{ $crumbs->title() }}
            </a>
        </li>
    @else
        <li class="breadcrumb-item active">
            {{ $crumbs->title() }}
        </li>
    @endif
@endforeach

@tabuna
Copy link
Member Author

tabuna commented Apr 21, 2020

It is also worth immediately adding support for short functions.

Route::get('/about')->name('about')->breadcrumbs(fn ($trail) =>
    $trail->parent('home')->push('About')
));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant