Level 75
Jan 24, 2021
2
Level 3
Laravel 8 cant get session variables in AppServiceProvider
I would like to share some variables from session in all views in Laravel 8. According documentation I call View::share() method in AppServiceProvider:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
//
}
public function boot()
{
// Variables shared in all views.
View::share('showModal', session('showModal'));
}
}
The problem is that although session showModal key is really set, I cant get it in AppServiceProvider::boot(). If I call session('showModal') in controller on in view I can see the correct value. Only AppServieProvider returns null. Can somebody explain me please what is wrong with this code? Thanks a lot.
Please or to participate in this conversation.