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

thc1967's avatar

Passing a variable into a Blade @include - Variable Not Defined

This seems to be the way the documentation suggests to do it.

In my parent Blade template, I have:

 @include('layouts.forms.btnsavecancel', ['cancelRoute' => '/'])

In the layouts.forms.btnsavecancel, I have:

<a class="button" href="{{ $cancelRoute }}">

The result in Whoops is a variable not defined error on $cancelRoute.

This is using Laravel 5.5. Documentation I referenced: https://laravel.com/docs/5.5/blade#including-sub-views

0 likes
1 reply
thc1967's avatar

OK this totally doesn't make sense. When I do a simple test with it, even nesting includes and sections relatively deeply, it works.

It doesn't work in more complicated code.

Has to be some weird Blade caching going on that php artisan view:clear doesn't resolve. When I work my way down the tree from my master layout into where the fields were failing, one level at a time, it works all the way down.

Frustrating.

Need beer.

4 likes

Please or to participate in this conversation.