laravel sahre data in all views code example
Example 1: Pass all data to all pages laravel
use Illuminate\Support\Facades\View;
class BaseController extends Controller
{
public function __construct()
{
$user = User::all();
View::share('user', $user);
}
}
Example 2: laravel data share all views
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
}
public function boot()
{
View::share('key', 'value');
}
}