Laravel 5 - session put not working

旧时模样 提交于 2020-02-25 04:53:47

问题


Any ideas why the session variable is not set with this code ?

public function commitTransaction($cluster,$transId)
{
    try {
        $response = $this->client->request('PUT', 'https://' . $cluster . '/' . $transId, [
            'auth' => ['id', 'pass'],
            'proxy' => '',
            'verify' => false,
            'json' => [
                'state' => 'VALIDATING'
            ]
        ]);
    $res = $response->getBody()->getContents();    
    session()->put('commit',$res);
        //dd($res);
    return $res;
    }
    catch (RequestException $e){
        var_dump($e->getResponse()->getBody()->getContents());

    }
}

The request is initiated on my constructor.

Thanks for your help.


回答1:


Try replacing your session put line from

session()->put('commit',$res);

To

Session::put('commit', $res);


来源:https://stackoverflow.com/questions/34708756/laravel-5-session-put-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!