Laravel dynamic breadcrumbs with links

Wasif Iqbal picture Wasif Iqbal · Jun 22, 2016 · Viewed 17.3k times · Source

I am trying to implement dynamic breadcrumbs in laravel with links. I successfully render the breadcrumbs but without links by following code.

    <ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"></i>Marketplace</a></li>
    @foreach(Request::segments() as $segment)
    <li>
        <a href="#">{{$segment}}</a>
    </li>
    @endforeach
</ol>

But now i am facing issue with the urls. I am getting the current url of the route with all the decendents. Can someone please help me that how can I add links to the breadcrumbs ?

Thanks.

Answer

user1669496 picture user1669496 · Jun 22, 2016

If I understand your issue correctly, you just need to fill in the URL of the link. This is untested but I think it should work.

<ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"></i>Marketplace</a></li>
    <?php $segments = ''; ?>
    @foreach(Request::segments() as $segment)
        <?php $segments .= '/'.$segment; ?>
        <li>
            <a href="{{ $segments }}">{{$segment}}</a>
        </li>
    @endforeach
</ol>