McRui
McRui

Reputation: 1931

Laravel eloquent multi relations search column

Trying to figure out how to make a search on a specific table from the below Laravel Eloquent query:

$user = \App\User::with('profile', 'languages', 'contacts', 'photos', 'jobs', 'offices', 'socials')->get();

What I'm trying to filter is a user where in the profile table the 'full_name_slug', '=', 'john-doe'

I've tried forming the where clause like 'profile.full_name_slug', '=', 'john-doe' but without success.

Probably this is quite simple but couldn't figure it out from all the Laravel 5 documentation.

Thanks in advance for any help Cheers

Upvotes: 2

Views: 83

Answers (1)

Mahdi Younesi
Mahdi Younesi

Reputation: 7489

The right syntax to do

User::whereHas('profile', function ($query) {

   $query->where('full_name_slug', '=', 'john-doe');
})->get();

Upvotes: 5

Related Questions