我正在我的laravel项目中实现rest api。我想保存我在会话中从api响应中获得的访问令牌。当我尝试使用此代码时,邮递员会显示以下错误:会话存储未按请求设置
<?php
namespace App;
use Illuminate\Http\Request;
class AuthSession{
private $oAuthHeader;
private $request;
public function __construct(Request $request)
{
$this->oAuthHeader = [];
$this->request = $request;
}
/**
* @return string
*/
public function getAccessToken()
{
if($this->request->session()->has('accessToken'))
echo $this->request->session()->get('accessToken');
else
return null;
}
/**
* @param string $accessToken
* @return AuthSession
*/
public function setAccessToken($accessToken)
{
$this->request->session()->put('accessToken',$accessToken);
return $this;
}
}