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

lifesound's avatar

Where auth()->id() Query result

I have this query

       // Item.php
		dd($this->assignments(function ($assignment) {
            return $assignment->where('user_id', auth()->id());
        })->get());

I opened it in 2 different browsers, although the result is one item belongs to one user It gives the same results on both users/browsers

as in photo https://ibb.co/kc52jP9

0 likes
9 replies
tykus's avatar
tykus
Best Answer
Level 104

What is that query supposed to be doing? If assignments is a relationship, then the syntax is:

dd($this->assignments()->where('user_id', auth()->id())->get());
1 like
lifesound's avatar

@tykus ( where ) should apply to assignments not the item ( $this ) , so it has to be subquery?

lifesound's avatar

@Sinnbeck Yes that way it works I will give you the answer but how to apply the (where to item ) ..?

Sinnbeck's avatar

@lifesound you already resolved the item. It's a model. So there is no way to restrict it. If you need to restrict how you get it originally, then give an example of what you are doing now

1 like
Sinnbeck's avatar

@lifesound no its totally. We are all learning :) feel free to create a new thread if you need some further explanation

Please or to participate in this conversation.