I am currently working on a project using Laravel 7 with MySQL and Charts.js. I'm facing an issue in echoing/displaying the data of two columns ("player_name" and "kills") from my MySQL database in JSON format. Typically, Laravel provides a @foreach loop for displaying data like this:
@php
foreach($player_stats as $player) {
echo "['".$player->player_name."', ".$player->kills."],";
}
@endphp
However, I am unsure about how to incorporate this within my JavaScript/JSON code. Can someone help me out? Here is the error message I encounter along with the remaining parts of my code:
Error message:
Facade\Ignition\Exceptions\ViewException
Undefined variable: player_name (View: C:\wamp64\www\GeneralTesting\resources\views\show-players.blade.php)
...
More sections of code go here ...