d13r/laravel-breadcrumbs

Add automatic page breadcrumb when ?page=2 is set in the url

robjbrain opened this issue · 3 comments

Could we add an easier way to automatically add pagination based on the page=2 part of the url?

Consider this example:

public function getCategory($category) {
    $articles  = Article::where('category_id', '=', $category->id)->paginate(10);

    return View::make('category', ['category'=>$category, 'articles' => $articles]);
}

Breadcrumbs::register('blog', function($breadcrumbs)
{
    $breadcrumbs->push('Blog', URL::to('blog'));
});

Breadcrumbs::register('category', function($breadcrumbs, $category)
{
    $breadcrumbs->parent('blog');
    $breadcrumbs->push($category->name, $category->url);
});

If page is currently on page 2, this wouldn't be included in the breadcrumbs. You would have to do something like:

Breadcrumbs::register('category', function($breadcrumbs, $category)
{
    $breadcrumbs->parent('blog');
    $breadcrumbs->push($category->name, $category->url);
    if($page = Input::get('page')) {
         $breadcrumbs->push('Page '.$page, $category->url.'?page='.$page);
    }
});

It would be nicer if there was an option (perhaps it would require a config setting?) to automatically append a page number to the breadcrumbs if it is set.

d13r commented

I'm not sure about making that part of the plugin as-is - but perhaps some additional methods could be added for before/after so you can do things like this:

Breadcrumbs::before(function($breadcrumbs) {
    $breadcrumbs->push('Home', route('home'));
});

Breadcrumbs::after(function($breadcrumbs) {
    if ($page = Input::get('page')) {
         $breadcrumbs->push('Page '.$page, Request::url() . '?page='.$page);
    }
});
d13r commented

Laravel Breadcrumbs is no longer officially maintained
Please see the README file for further details.

d13r commented