I want to make a singleton binding of a domain model in register method of AppServiceProvider, but I have saved the id of the selected model in session and this information is not accessible in AppServiceProvider.
Has somebody any idea how I can solve my problem? This is my code.
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(Domain::class, function ($app)
{
$request = request();
if ($request->has('d'))
{
session(['domain' => $request->get('d')]);
$domain = Domain::find($request->get('d'));
}
else
{
$domain = Domain::find(session('domain'));
}
return !is_null($domain) ? $domain : new Domain();
});
}
public function boot()
{
//
}
}
session('domain') is always null.
Thank you