Support the ongoing development of Laravel.io →
Database Eloquent

My database structure like this: category: id, name Parents: category_id parent_id

id has parent categories like id used in parents model as foreign key category_id against have parents parent. parent_id actually is categor id. I want to get records like this SELECT category.name FROM category INNER JOIN category_parents ON category.id = category_parents.category_id WHERE category_parents.category_id=79 but in eloqent model relation ship.

Last updated 2 years ago.
0

https://laravel.com/docs/5.2/eloquent

There's also some "advanced wheres" somewhere in the documentation.

0

Thanks for reply me. But i want where clause in eloquent relationship that described above.

0

Try using whereHas, eg.

->whereHas('RelationshipName', function($query) {
  $query('your-field', your-condition);
})
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.