Laravel @foreach Repeating Same Data

71 Views Asked by At

when I am trying to add @foreach 3 times it's repeating my data. how do I solve this? and am using Livewire.

Small Summery : I will try to make a Student Management system using Laravel and livewire. basically, I am trying to make a payment system based on Monthly, Termly, and Year so it's also separate to more. Example We have Different price Value of Monthly Payment Scheme Students.

this is my code

 public function mount($students){
        $students = Student::With('FeeScheem','FeeScheemInd','FeeGroup','FeeMaster','FeeCollector')
        ->where('students.stu_id',$students )
        ->get();
        $this->students = $students;
     
        // DD($students);
    }

Eloquent Relationship

public function FeeScheem()
    {
        return $this->hasOne(FeeScheem::class, 'fs_id', 'stu_fee_scheems');
               
    }
    public function FeeScheemInd()
    {
        return $this->hasOne(FeeScheemInd::class, 'ind_id', 'stu_ind_fee_scheems');
        
    }

    public function FeeGroup()
    {
        return $this->hasMany(FeeGroup::class, 'fee_group_fee_scheem_id', 'stu_fee_scheems');
    }

    public function FeeMaster()
    {
        return $this->hasOne(FeeMaster::class, 'fee_master_ind_fs_id', 'stu_ind_fee_scheems'); 
    }

    public function FeeCollector()
    {
        return $this->hasMany(SchoolFeeCollector::class, 'fc_stu_id', 'stu_id');
    }

This is My Blade File

<tbody>
  
  @foreach($students as $Student)
  
  @foreach($Student->FeeGroup as $FeeG)
  
  @foreach($Student->FeeCollector as $FeeC)
  
  
  
    <tr>
      <td></td>
      <td>{{$FeeG->fee_group_name}}</td>
      <td>{{$FeeG->fee_master_due_date}}</td>
      <td></td>
      <td>{{$Student->FeeMaster->fee_master_amount}}</td>
    </tr>
   
@endforeach
@endforeach
@endforeach
  </tbody>

Here the table view in Blade file

0

There are 0 best solutions below