Function that stores session does not work when requested via post. Laravel 5.4

0

I'm having a problem inserting a session using Laravel 5.4.36. Next: when I insert the session via get (getUserSession function) it works perfectly. When I insert the session via post (vulgo putUserSession) it simply does not insert the data. The result of request arrives in the normal function. The route is in the web middleware.

Function code:

/**
* Método que insere o usuário na sessão
*
* @param $request
* @return array
*/
public function putUserSession(Request $request) {
    // session()->forget('usuario');
    session()->put('usuario', $request->usuario);
    return [$request->usuario];
}

/**
 * Método que retorna o usuário que foi inserido no sessão
 * 
 * @return string
 */
public function getUserSession() {
    // session()->put('usuario', 'wes');
    return session()->get('usuario');
}

Call code in auth.js:

fetch('inserirusuario', {
                method: 'post',
                headers: {'Content-Type':'application/json'},
                body: JSON.stringify({usuario:this.username})
            }).then(function(response) {
                return response.json();
            }).then(function(data) {
                console.info(data);
            });
    
asked by anonymous 05.03.2018 / 20:27

0 answers