Programador Adagal Programador Adagal - 1 year ago 133
PHP Question

Laravel 5.1 - Pass parameter to Breadcrumbs

I use davejamesmiller Breadcrumbs package. I am wondering how to pass a parameter to a breadcrumb, something like an id.

In the docs (here) it says that is possible, but can't find the way to do it.

My goal es to do a breadcrumb like this:

Dashboard \ User \ New Model
. Where New Model its a form to add model data with some relationship with the user. Without the user_id param the link for
won't work.

Any idea?

Answer Source

You can pass global variable

\View::share ( 'variable2', $variable2 );

if render breadcrumbs in layout

or You need render breadcrumbs in `user.new_model.blade

{!! Breadcrumbs::render('page', $page) !!}

my way

Create template


with content

    <ol class="breadcrumb">
    <li>{!! link_to_route('main', 'Home') !!}</li>
    @foreach($breadcrumbs as $bread)
            <li>{!! link_to($bread['url'], $bread['name']) !!}</li>
            <li>{!! $bread['name'] !!}</li>

and connect it to layout


and in your action pass array of links

\View::share('breadcrumbs', [
        ['url' => route('', ['id'=>$data->collection, 'url'=>$data->collection]), 'name' => $data->collection->name],
        ['name' => $data->article]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download