Programador Adagal Programador Adagal - 1 month ago 10
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
User
won't work.

Any idea?

Answer

You can pass global variable

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

if render breadcrumbs in layout

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

@section('content')
{!! Breadcrumbs::render('page', $page) !!}
@stop`

my way

Create template

breadcrumbs.blade.php

with content

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

and connect it to layout

@include('breadcrumbs')

and in your action pass array of links

\View::share('breadcrumbs', [
        ['url' => route('collection.show', ['id'=>$data->collection, 'url'=>$data->collection]), 'name' => $data->collection->name],
        ['name' => $data->article]
    ]);