laravel data share all views code example
Example 1: Pass all data to all pages laravel
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Auth;
use DB;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
View::share('key', 'value');
Schema::defaultStringLength(191);
$categories=DB::table('categories')->get();
View::share('categories',$categories);
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
Example 2: laravel data share all views
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
View::share('key', 'value');
}
}
Example 3: Pass all data to all pages laravel
this work :)
use Illuminate\Support\Facades\View;