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.
Facebook Login With PHP Laravel Socialite
Resolve 404 Not Found In NGINX
Install Letsencrypt SSL Certificate for RabbitMQ Server and RabbitMQ Management Tool
Route Model Binding In Laravel & Change Default Column id To Another Column
Use Different PHP Versions In Ubuntu / Linux
Supervisor For Laravel Queue Scheduling
Securely Connect Server MYSQL DB From Sequel Pro / MYSQL Workbench
Website Speed and Performance Optimizations
Automate Repeating Tasks In Linux Server With Cronjobs
Sass or SCSS @function vs @mixin
Foreign Key Migrations Simplified In Laravel 7.x
Custom Validation Rules In PHP Laravel (Using Artisan Command)