Pass all data to all pages laravel 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: 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
{
public function boot()
{
View::share('key', 'value');
Schema::defaultStringLength(191);
$categories=DB::table('categories')->get();
View::share('categories',$categories);
}
public function register()
{
}
}
Example 3: Pass all data to all pages laravel
this work :)
use Illuminate\Support\Facades\View;
Example 4: use varable on all site pages laravel
{{Session::get('website_name', 'Value Goes Here')}}
Example 5: use varable on all site pages laravel
php artisan make:middleware SomeMiddleware
Example 6: use varable on all site pages laravel
public function boot()
{
view()->share('someKey', 'This is shared data');
}