Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jhyaps's avatar

Laravel Dynamic Breadcrumb Blade page

Hello everyone, i am creating a breadcrumb blade where a breadcrumb will be dynamic for all pages

Firstly in the create, index, edit, trash blade i include

@include('backend.includes.breadcrumb', ['title' => 'users', 'method' => 'edit', 'route' => 'users'])

and in breadcrumb.blade.php

<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
    <div class="breadcrumb-title pe-3">{{ $title }}</div>
    <div class="ps-3">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb mb-0 p-0">
                <li class="breadcrumb-item"><a href="{{ route('backend.dashboard') }}"><i class="bx bx-user"></i></a></li>
                <li class="breadcrumb-item"><a href="{{ route('backend.'. $route.'.index') }}">{{ $title }}</a></li>
                <li class="breadcrumb-item active" aria-current="page">{{ $method }}</li>
            </ol>
        </nav>
    </div>
    <div class="ms-auto">
        <div class="btn-group">
            <a class="btn btn-primary" href="{{ route('backend.'. $route.'.'. $method .'') }}">Add New</a>
        </div>
    </div>
</div>

but the problem is, only {{ $title }} value is coming, not others.

it says

Undefined variable $route
Undefined variable $method

How can i solve this issue ? any one ??

0 likes
5 replies
ramonrietdijk's avatar

The syntax of your code seems fine. Are you sure that you are not including this file at a different location, without the method and route?

jhyaps's avatar

@ramonrietdijk

Actually, i will set my location only for create edit, index and trash for all pages. that means method and route will be there.

Why only the $title value is shown not others ?? thats my questions.

ramonrietdijk's avatar

@jhyaps By "location" I meant I was wondering if you are including the breadcrumb view elsewhere without the extra options, resulting in undefined variables.

By passing the array with all required keys, you should not get this error.

So, are you sure you are not including the backend.includes.breadcrumb file somewhere, without these extra parameters?

jhyaps's avatar

@ramonrietdijk Hi, Yes, I am including my breadcrumb in all view page, but the idea i tried was wrong so , i designed by breadcrumb like , if i want to pass data, i will pass through the parameter like this

@include('backend.includes.breadcrumb', ['page' => 'Users', 'method' => 'Edit', 'route' => 'backend.users.create', 'link' => 'backend.users.index', 'add_btn' => 'yes'])

& if i dont want i will pass through empty value

@include('backend.includes.breadcrumb', ['page' => 'Dashboard', 'method' => '', 'link' => '', 'route' => '', 'add_btn' => ''])

Though this idea solves the problem but still don't know still it is good approach to do it or not

ramonrietdijk's avatar
Level 30

@jhyaps You could pass empty values, but I'd personally prefer to not pass them to the view at all. In your breadcrumb template, you could safely check the existence of the variables.

...
@if(isset($title))
    <div class="breadcrumb-title pe-3">{{ $title }}</div>
@endif
...

If you introduce new variables in the future, they won't break and you don't have to update all implementations to pass an extra empty value.

1 like

Please or to participate in this conversation.