@afoysal You don’t, because you shouldn’t be trying to access session variables in a service provider at all.
Jul 16, 2021
6
Level 8
Session::get('') inside boot() of AppServiceProvider
How can I get access of Session::get('') inside boot() function of AppServiceProvider class ?
My code is like below
<?php
namespace App\Providers;
use App\Models\Cashier\Subscription;
use App\Models\Cashier\SubscriptionItem;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Laravel\Cashier\Cashier;
use Config;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Session;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
Cashier::useSubscriptionModel(Subscription::class);
Cashier::useSubscriptionItemModel(SubscriptionItem::class);
try {
$response = Http::withToken(Session::get('SesTok'))->get('someURL');
$number = count($response->json()['logs']);
View::share(['number'=>$number]);
} catch (Exception $exception) {
//some code
}
}
}
Please or to participate in this conversation.