jeudi 8 février 2018

HasMany Relation Return Only One array

I'm not so good at coding. I have a problem, I try to get data from another table by user_id, I can take a data Row but next Row are empty. here is my code:

class PointSpeech extends Model
{
  protected $fillable = ['user_id', 'points_earned', 'points_request', 'pay_by', 'is_pay', 'points_pending',];

  public function staff(){
    return $this->hasMany(Staff::class, 'user_id');
  }

}

I want to get my Staff By PointSpeech Model. My Staff Model is:

class Staff extends Model
{
  protected $table = 'users';
  protected $fillable = ['id', 'name', 'email', 'password', 'api_token', 'NID', 'mobile_number', 'bikash_number', 'rocket_number', 'gender', 'birth_day',];

  public function PointSpeech(){
    return $this->hasMany('App\PointSpeech');
  }
}

now I want to print it as

@foreach($speech_req as $key => $speech)
<tr>
   <td>
      @foreach($speech->staff as $staf)
        
      @endforeach
    </td>
    <td></td>
    <td></td>
    <td>
        @foreach($speech->staff as $staf)
            @if($speech->pay_by === 'rocket') 
                Rocket Number : 
            @elseif($speech->pay_by === 'bikash')
                Bikash Number : 
            @endif
        @endforeach
    </td> 
</tr>
@endforeach

it returns a single row of data. but I need all of them. I think it's easy for you guys. please help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire