Support the ongoing development of Laravel.io →
Eloquent

Hello, I'm new on Laravel, and I need some help to build this query. My clients have many contacts, I want to get all clients, but only return the contact marked as main. It´s possible with Eloquent, or I need to use Query. Please if is possible to put a example.

Last updated 3 years ago.
0
$clients = Client::leftJoin('contacts', function($join) {
		$join->on('client.id', '=', 'contacts.client_id');
	})
	->where('contacts.type','=','main')
	->get();

maybe something like this?

Last updated 10 years ago.
0

Perfectly, thanks for your help!!! Now I understand the concept. Sorry my bad english :)

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.