how to pass value in app.blade code example

Example: how to pass value in app.blade

//create a service provider
php artisan make:provider ComposerServiceProvider
  
//register the app service provider in providers array of config/app.php
App\Providers\ComposerServiceProvider::class,

//pass the data you want to share in views 
<?php 
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

class ComposerServiceProvider extends ServiceProvider {

    public function boot()
    {
        View::composer('*', function($view){
            $data = Some logic here ; //eg User::all();
            $view->with('data', $data); // 'data' is value to be used in views 'data' = $data
        });
    }

    public function register()
    {
        //
    }
}

Tags:

Php Example