Support the ongoing development of Laravel.io →
Database Eloquent

I'm converting roject from pure PHP to Laravel 4, and I have a problem with converting this query

SELECT * FROM verses,thoughts WHERE verses.id != thoughts.verses_id

I have two tables verse and thought. one verse has one thought. when creating a thought i want to display all the verse whose thoughts has not been created . Im using Laravel 4.2 display the verses it is not listed in thoughts

Last updated 2 years ago.
0

Turn on debug mode. lists() method returns array, which doesn't have join() method. Plus, you'd probablu want to use relations instead of pure joining.

Last updated 2 years ago.
0

Assuming you're using Eloquent models:

$thoughts = Thought::all();

$unused_verses = Verse::whereNotIn('id', $thoughts->list('verse_id'))->get();

Then make your list however you want:

foreach ($unused_verses as $verse)
{
   // do stuff here...
}
Last updated 2 years ago.
0

thnks..

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Bribin bribin Joined 8 Jul 2014

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.

© 2025 Laravel.io - All rights reserved.