Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adhik13th's avatar

How to showing data on blade with pass through 2 table FK

I have 3 table like users , data_users , practice

users      : id , name ,dob ,email , etc . . .

data_users : id , user_id , number_exp , etc . .

practice   : id , data_user_id , practice_number , etc ....

in 3 tables connect by relation belongsTo and and want to showing this . i want to show data on table practice :

My controller :

public function show()
{
    $practice= Practice::with('data_users')->get();

    return view('admin.practice' ,['practice'=>$practice]);
}

my view

 <table class="table table-bordered">
              <thead>
                <tr>
                  <th>No</th>
                  <th>Name</th>
                  <th>No Surat</th>
                  <th>Date</th>
                  <th>Status</th>
                </tr>
              </thead>
              <tbody>
                @foreach ($practice as $i)
                <tr>
                  <th scope="row">1</th>
                  <td>{{ $i->data_users->users->name}}</td>//i want to show name but i cant show this
                  <td>{{ $i->practice_number}}</td>
                  <td>{{ $i->practice_date}}</td>
                  <td>{{ $i->status}}</td>
                </tr>
                @endforeach
              </tbody>
            </table>

i have problem to showing Data 'NAME' form table users , and i just can showing id from data_users

but still error Trying to Get property

0 likes
5 replies
Tray2's avatar

Have you set up the proper relationships in you models?

public function users()
{
    return $this->belongsTo(User::class);
}
mvd's avatar

Hi @adhik13th

You pass the $practice variable/query result but in your view you use $riwayat

adhik13th's avatar

ups iam sorry for my typo sir, i update my thread

mvd's avatar

@adhik13th it's hard to see what is wrong without code. Can you give us the relations (code) ?

Please or to participate in this conversation.