1

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 ?

1 Answer 1

1

I found the solution, when i was retrieving the data to the view the array session of this type $request->session()->get('session_products'), i was sending a bidimensional array, where 'session_products' was on row 1,2,3,4 etc and column 0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.