Support the ongoing development of Laravel.io →
Views Blade Architecture

Hello Guys,

I have used View Composers in which it manipulates some data from Database and shares the data to every view. And also I have been using multiple separate views inside the main view. Database queries are fetching for every sub view also.. I need View composers to executed for Main view alone which renders master layout. Is there any choice to restrict views composers to work only for the Main view ? We have 100-200 Main pages. It will be difficult to add them in the composer service provider like this

View::composer( ['profile', 'dashboard'], 'App\Http\ViewComposers\MyViewComposer' );

I dont want to use this also View::composer( '*', 'App\Http\ViewComposers\MyViewComposer' );

Example: main-view.blade.php

<div>Test</div> include('sub-view1') include('sub-view2') include('sub-view3')

I need to run only for Main view...

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Nandakumar nandakumar Joined 22 Sep 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.