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.
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
public function boot()
{
View::composer('*', function($view){
/** You can also add with some condition */
if(Session::has('user_details')){
$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.
Sass or SCSS @mixin vs @extends vs Placeholder (%)
Generate RSS Feeds in PHP Laravel
Accessors And Mutators In PHP Laravel
Unable to prepare route [{fallbackPlaceholder}] for serialization. Uses Closure In Laravel
Google, Twitter, GitHub, Facebook & Many Other Social Generic Logins With PHP Laravel Socialite
What Is HTTP? Different HTTP Methods And Status Codes Explained With Examples
Getting Started With AMP (Accelerated Mobile Pages)
Laravel Clear Cache Of Route, View, Config Command
Global Data In All Laravel Blade Pages
Lazy Load YouTube And Other Videos In Website
Dependency Dropdowns With Javascript And PHP
Install Packages Parallel For Faster Development In Composer