Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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
AppProvidersComposerServiceProvider::class,

//pass the data you want to share in views 
<?php 
namespace AppProviders;
use IlluminateSupportFacadesView;
use IlluminateSupportServiceProvider;

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()
    {
        //
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pass
ADD COMMENT
Topic
Name
7+3 =