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

ctf0's avatar
Level 2

how to share @php block across partials

lets say we have a var call routeName that we want to share across several views,

@php
    $routeName = Route::currentRouteName();
@endphp 

so maybe we make a partial vars.blade.php and include it in each view we want this var

@include('_partials.vars')

but unfortunately this doesnt work, and i keep getting Undefined variable: routeName.

i tried to use @set but nothing changed, so did anyone came across such scenario ?

0 likes
0 replies

Please or to participate in this conversation.