Laravel 5.5 Rest API会话存储未根据请求设置

时间:2018-03-08 11:17:25

标签: api session laravel-5.5 laravel-session

我正在我的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;
}
}

0 个答案:

没有答案