在laravel的构造函数中使用会话值
我一直坚持在_构造函数中使用会话值,但它显示空值。我还在kernel.php中添加了一些配置,但仍然不起作用。请帮忙在laravel的构造函数中使用会话值,laravel,Laravel,我一直坚持在_构造函数中使用会话值,但它显示空值。我还在kernel.php中添加了一些配置,但仍然不起作用。请帮忙 public function __construct() { /** PayPal api context **/ $this->middleware(function ($request, $next) { $paypal_conf = \Config::get('paypal'); $orgId=Session::get
public function __construct()
{
/** PayPal api context **/
$this->middleware(function ($request, $next) {
$paypal_conf = \Config::get('paypal');
$orgId=Session::get('org_id');
$org_credentials=PaypalCredentials::where('org_id','=',orgId)->first();
$credentials=$org->paypalCredentials;
$this->_api_context = new ApiContext(new OAuthTokenCredential(
$credentials->client_id,
$credentials->client_secret));
$this->_api_context->setConfig($paypal_conf['settings']);
return $next($request);
});
}
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
];
我们需要更多的信息来提供帮助。在正常情况下,如果这是一个web路由,并且设置了
org\u id
,并且会话cookie传递正确,那么您的代码应该可以工作。我们无法合理地知道您提供的信息量在这种情况下有什么问题。也不要在每个路由中启动会话。会话在api路由中没有意义
public function __construct()
{
/** PayPal api context **/
$this->middleware(function ($request, $next) {
$paypal_conf = \Config::get('paypal');
$orgID = $this->getSession('org_id');
$org_credentials=PaypalCredentials::where('org_id','=',orgId)->first();
$credentials=$org->paypalCredentials;
$this->_api_context = new ApiContext(new OAuthTokenCredential(
$credentials->client_id,
$credentials->client_secret));
$this->_api_context->setConfig($paypal_conf['settings']);
return $next($request);
});
}
private function getSession(){
return \Session::get('org_id');
}