Good content takes time and effort to come up with.

Please consider supporting us by just disabling your AD BLOCKER and reloading this page again.

Global Data In All Laravel Blade Pages | StackCoder

Global Data In All Laravel Blade Pages

08th August 2020 1 min read
Share On     Share On WhatsApp     Share On LinkedIn

Most of the time you might require some generic data which needs to be made available across all the Laravel Blade pages.

For example, you might need a count of categories in your sidebar.

Adding Generic View Data In AppServiceProvider.php

To make data available generic across all the view pages one of the simplest ways is to add it in AppServiceProvider.php boot function as shown below

app/Providers/AppServiceProvider.php - boot() method

public function boot()
    View::composer('*', function($view){
        /** You can also add with some condition */
            $view->with('projectCountDetails', ProjectsController::projectCountDetails());

From the above code, we will be able to access the projectCountDetails variable across all the view pages as shown below.


Hope this article helped you. Please share it with your friends.

Author Image

Channaveer Hakari

I am a full-stack developer working at WifiDabba India Pvt Ltd. I started this blog so that I can share my knowledge and enhance my skills with constant learning.

Never stop learning. If you stop learning, you stop growing