
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.
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.
Resolve 404 Not Found In NGINX
Client-Side DataTable, Adding Super Powers To HTML Table
Laravel 7.x Multiple Database Connections, Migrations, Relationships & Querying
Setup MAMP Virtual Hosts For Local PHP Development
Lazy Load Images In Chrome With This Simple Trick
Proper Way To Validate MIME Type Of Files While Handling File Uploads In PHP
Setup Docker for NodeJs, MongoDB, MongoDB Compass
Create Gmail App Password For SMTP Mails
Firebase Cloud Messaging (FCM) Browser Web Push Notifications Using Javascript And PHP
What Is Composer? How Does It Work? Useful Composer Commands And Usage
Foreign Key Migrations Simplified In Laravel 7.x
PHP file_put_contents failed to open stream: Permission denied