There are days when I'm banging my head to read data from a Session
through a ajax
call
.
In an application without Framework
I do this normally using PHPSESSION
, but in Laravel 5.7
I can not do it at all.
My environment: Ubuntu Server + PHP 7.2 + Laravel 5.7 using file as session driver
My ajax
call
:
$.ajax({
url: '/nota/consulta?id_cliente='+id_cliente+'&item='+item,
dataType: 'json',
success: function(result) {
console.log(result);
}
});
My controller:
public function getNota(Request $request)
{
if ($request->session()->has('nota'))
{
$nota = $request->session()->get('nota');
return response()->json($nota);
}
return response()->json(array('msg'=>'erro'));
}
The session then exists because it starts with View
, but the result of ajax
does not show the data. I believe I have something in Laravel
that is preventing me from reading data from the Session when the request is made by Ajax, because if I open the link in the browser the data appears.