Now in the html table

I'm displaying the numbers brought from laravel and controller in
At that time, it is set with javascript so that the numbers are separated by commas.

However, the comma separation is reflected only in the first row of the table,
It will not be reflected after the second line.
What's wrong
I would appreciate it if you could point me out.
Thank you.

Current state ↓

When you bring the list display page on the laravel blade screen
I want to display them separated by commas. 60000000 in the photo is the value of {{$date->goal}}

(Omitted in the middle)
                @foreach ($getData as $data)
                      <td id = "goal">{{$data->goal}}</td>← value of 60000000 in the photo
                      <td id = "result">{{$data->result}}</td>

window.onload = function(){
// when the page loads
  var goal = {{$data->goal}};
  var result = {{$data->result}};
  var retGoal = Number(goal).toLocaleString();
  var retResult = Number(result).toLocaleString();
  document.getElementById("goal").innerHTML = retGoal;
  document.getElementById("result").innerHTML = retResult;
  • Answer # 1

    IDs must not be duplicated.

    In this case, it seems easier to process on the PHP side, but if you do it with JavaScript, specify the same class for the td you want to process. It can be realized by looping it with JS and performing existing processing.

  • Answer # 2

    It was easier to do it on the PHP side, so I implemented it there.

    $getData = DB::select(DB::raw('select format(goal,0) as goal,format(result,0) as result from table'));

    I passed this to blade and displayed it in three-digit division.