如何修复“NULL不是有效的DataTable。” - Laravel Lavacharts

I have my data in an array and I'm trying to display the information in a Lavacharts Donut Chart, I've hit a wall since I'm not sure why it is erroring out, when I dump the variable ($counted_heroes) it looks fine but I'm not an expert with arrays.

I have googled the error but it only lead to a github issues page where it was unfortunately never resolved, I've looked at the Laravel "arguments" section of the error to see why it is erroring, it looks fine from my perspective with no empty values.

function index()
{
    $heroes = \Lava::DataTable();
    $heroes = DB::table('replays')->leftJoin('heroes', 'heroes.id', '=', 'replays.hero_id')->select(DB::raw('replays.hero_id as hero_id, heroes.hero_name as hero_name'))->get()->toArray();
    foreach($heroes as & $hero) {
        $hero = ['hero' => $hero->hero_name, $hero->hero_id, ];
    }

    $counted_heroes = array_count_values(array_column($heroes, 'hero'));
    \Lava::DonutChart('Heroes', $counted_heroes, ['title' => 'Heroes Played']);
    return view('public.stats', compact('lava'));
}

The expected outcome of this would be that the array is accepted by the Lavachart and the data is displayed, instead of this unfortunate error.

Any help would be most appreciated! <3

Thank you.

compact() assumes that $compact variable is defined before.

You didn't defined it inside your index() method.

Try return view('public.stats', compact('heroes'));, your view is expecting not an array, but a certain library object, as it was mentioned by ourmandave. Note, that you have to replace lava to heroes in your view than.