1

1

This is my table: hms_bbr_category_2. It's just a test table, ignore the gibberish.

I need to get a console.log working so that just in case values there will be any null data when I add new rows

Here is my Laravel controller: (my model is HmsBbrCategory and connects to the table)

public function fetchcategory() {
    $all_categories = HmsBbrCategory::all();
    return response()->json([
        'all_categories'->$all_categories,
    ]);
}

Ajax

function fetchcategory() {
    $.ajax({
        type: "GET",
        url: "/clinical/bbr-category-configuration-data",
        dataType: "json",
        success: function (response){
            console.log(response.all_categories);
        }
    });
}

My console is giving out this error when I try to show the table:

2

message: "Trying to get property (list of the table arrays) of non-object"

Does the error show because some of my columns have null? what can I do to output the data even with the null values?

1
  • I think you have syntax error. Use => instead of -> in your controller. Commented Jun 18, 2021 at 8:49

2 Answers 2

1

You have error while returning response 'all_categories'->$all_categories,

public function fetchcategory(){
    $all_categories = HmsBbrCategory::all();
    return response()->json([
        'all_categories'=>$all_categories,
    ]);
}
0

You have an error while returning your JSON response in your fetchcategory() method:

In place of this line of code:

return response()->json([
    'all_categories'->$all_categories,
]);

Use this line of code:

return Response::json(array('all_categories' => $all_categories));