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

alexlords's avatar

laravel 6

My question would be, i have my layout view, but what i want to do is insert a dynamic sub-bar into that layout which will change depending on what section of the web platform you are in. ? how would be the best way of going about that by staying within laravel framework structure ?

clearly my journey starts in the routes web.php file as the route will determine what will be displayed in the subbar ?, do i direct it to a controller first ?

0 likes
7 replies
Snapey's avatar

No, in the view, load content according to the current path.

for instance

@if (Route::has('admin'))

    @include('_admin_sub-bar')

@else 

    @include('_user_sub-bar')

@endif

checks if the URL contains certain parameters and then includes menu a or menu b

alexlords's avatar

Hey Snapey, thank you for the start direction, so i could use this include to direct to a class to construct the sub-bar using the route value as the key ?

alexlords's avatar

Hey Snapey,

Thank you for this direction, i will def use it for my project, my only question about the route is that it is the only data source to tell the data which section it currently is in and the section it is in is critical to to the view of the subbar on that section

Snapey's avatar

your view is deciding which subnav to show, and when it is rendered it has access to the request object

alexlords's avatar

Hey Snapey,

thank you for the information was really helpful.

Snapey's avatar
Snapey
Best Answer
Level 122

Please mark best answer if it solves your problem

Please or to participate in this conversation.