Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreach only return first value

Not sure why it is not getting all the value In my view

<?php $sum_selfmark =0?>
  @foreach
      ($criteria_criteriamarks as $criteria_criteriamark)

      SelfMark:{{$criteria_criteriamark->selfmark}}
      <?php $sum_selfmark+= $criteria_criteriamark->selfmark ?>

  @endforeach
      <p>Total:{{$sum_selfmark}}</p>

In my controller

 public function go_to_self_marking($id){
    $criteria=Criteria::find($id);
    $criteria_criteriamarks =$criteria->criteriamarks;
    return view('criterias/self-marking')
    ->with('criteria_criteriamarks',$criteria_criteriamarks);
    }
like image 444
Donald Donald Avatar asked May 12 '26 23:05

Donald Donald


1 Answers

You are trying to for each a 1 row. Because $criteria=Criteria::find($id); returns only 1 row.

If you want to for each then use $criteria=Criteria::all(); It will return all the row in your Criterias Table.

like image 113
MONSTEEEER Avatar answered May 14 '26 17:05

MONSTEEEER



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!