N
N
NikolayAlb2017-04-15 17:47:50
Laravel
NikolayAlb, 2017-04-15 17:47:50

Laravel 5.4. How to make the logic of the formation of breadcrumbs correctly?

Hello, I'm using a simple breadcrumbs package . I created a separate base controller, from which the rest are inherited, set in the constructor:

public function __construct()
    {
        $this->breadcrumbs = new \Creitive\Breadcrumbs\Breadcrumbs;

        $classes = array('breadcrumb', 'breadcrumb-item');
        $this->breadcrumbs->addCssClasses($classes);
        $this->breadcrumbs->setDivider('');

        $this->breadcrumbs->addCrumb('Home', route('home'));

    }

Now, from all child controllers, respectively, there is access to setting crumbs. Setting up is done by adding a new crumb, everything is extremely simple. But the bottom line is that this code heavily pollutes the code of the controller methods themselves, and writing in each method is a bad decision:
public function index(Request $request)
    {
      //...
        $this
            ->breadcrumbs
            ->addCrumb('Posts', '');
        $this
            ->breadcrumbs
            ->addCrumb('Post'.$request->post_id, route('post',['ost_id'=>$request->ost_id]));

       //...
    }

How can such a task be optimized? In terms of architecture.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maddog670, 2017-04-15
@NikolayAlb

Use the package https://github.com/davejamesmiller/laravel-breadcrumbs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question