Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

It looks like you are missing get.

$threads = Thread::whereHas('users', function($query) {
  $query->where('owner_id', auth()->user()->id);
})->get();
Last updated 8 years ago.
0

thomastkim said:

It looks like you are missing get.

$threads = Thread::whereHas('users', function($query) {
 $query->where('owner_id', auth()->user()->id);
})->get();

Thanks, I tried but it still doesn't work regardless get() or not

Last updated 8 years ago.
0

Hmm...I could think of / see two things.

  1. First, you need to access the pivot attribute on each individual user. If you take a look at the docs: http://laravel.com/docs/master/eloquent-relationships

You'll see that you need to loop through the related model (in this case, the user), and then access the pivot table.

  1. Does the users table have an owner_id? If not, that will also be a problem.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

hoandang hoandang Joined 29 Sep 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.