Level 88
You can chain relationships
$users = User::with('campus.university');
But I'm not really sure what you want to achieve here!
This might be useful to read: https://laravel.com/docs/5.8/eloquent-relationships#querying-relations
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
how can I achieve list of student in from university through campus .
db structure
universities
id
name
campuses
id
university_id
name
users
id
campus_id
students
id
user_id
Laravel has no native support for a direct relationship.
I've created a package for cases like this: https://github.com/staudenmeir/eloquent-has-many-deep
class University extends Model
{
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
public function students()
{
return $this->hasManyDeep(Student::class, [Campus::class, User::class]);
}
}
// $university->students
Please or to participate in this conversation.