what do u wants to know
Mar 11, 2019
13
Level 5
Show users not in table
I have 3 tables
users
items
items_sold
I need to provide list of users who have items listed but never sold any. Tables are connected like this
users
id | name
1 | Steve
2 | John
Items
id | item_name | user_id
1 | Toothpicks | 1
2| Anvils | 2
items_sold
id |sold_at| item_id
1 | [date] | 2
With the above as an example I would like to return this:
Steve
(because he has an item listed - toothpicks - but has never sold any)
Any help appreciated I'm really struggling.
Level 67
This is pretty easy if you're using Eloquent relationships. You could just use doesntHave() or whereDoesntHave() and get the users that don't have sales.
https://laravel.com/docs/5.7/eloquent-relationships#querying-relationship-absence
Please or to participate in this conversation.