samedi 8 septembre 2018

display pivot table multiple data into blade

I have a users table, meeting table, and a pivot table meeting_user. I need to show meeting table data and pivot table data. I can display normal foreign key data using the relationship method like @foreach($meetings as meeting) <td> where I am sending all meeting table data using $meetings = Meeting::all() But now I am storing multiple users so how can I show the name of those users that is stored in meeting_user table where the userType == 'host'. I have a field isHost that is a boolean type and 1 means it is host type user and 0 means it is visitor type user.

User Model

public function meetings()
{
    return $this->belongsToMany('App\Meeting')->withPivot('meeting_id', 'user_id');
}

Meeting Model

public function users(){

    return $this->belongsToMany('App\User')->withPivot('meeting_id', 'user_id');
}

view

   <tr>
    @if( )
    <td></td>
    @endif
    <td></td>
        <td></td>                      
    <td></td>                             
</tr>



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Ns2WpL
via IFTTT

Aucun commentaire:

Enregistrer un commentaire