How manipulate the request that i recived via AJAX (LARAVEL)?

  ajax, javascript, jquery, laravel, php

This is my code ajax that send the DATA

  $.ajax({
                url: '{{url("path")}}',
                data:  aux,
                type: 'POST',
                success:function(response){
                    console.log(response);          
                },
                error: function(response) {
                    console.log("error");
                }
            });

The problem is when i want manipulate this $request in my controller to create a new object with the datas that goes in the data.

this is my controller en laravel.

public function path(Request $request)
{
    
    $data = $request->all();
    #create or update your data here
    //dd($data["text"], $data["parent"],$data["text"]);
    //return response()->json([$data]);
    Tree::create([
        'idcodigo' => 'codigo',
        'descripcion' => 'descripcion',
        'idpadre' => '2',
    ]);
    return response()->json([$data]);

}

If i try to creater a new tree i have the problem because not create the tree::new.

In the console i see and the data is here.

Finally, i want send a data via ajax and use this data to insert the data in my database.

Any comment is fine thank you so much

Yes, i have the header to send the token.

Source: Laravel

Leave a Reply