I'm developing an eCommerce in Laravel 5.4. When the user press into "buy" button, i make a query with product id hidden into a input field. Then, i have a Product collection and then, insert them into an session array. This will be in future my buys cart
This is my controller method
public function agregarACarrito(Request $request){
$producto = new Producto();
$producto=Producto::where('id','=',$request->parametros)
->get();
$request->session()->push('session_products',$producto);
return json_encode($request->session()->get('session_products')) ;
}
And this is my AJAX script
function agregarACarrito(){
var parametros =$("#id").val();
$.ajax({
data:{parametros:parametros},
url:'/agregarACarrito',
type:'post',
dataType:"json",
success:function(data){
for(var i in data) {
$('#session').html("<li>"+data[i].modelo+"</li>");
}
}
});
}
The problem begins when i want to retrieve this array session into my view. Or i get object], or [undefined], or just an error in console.
What im doing wrong ?