Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alexMafus's avatar

how to show only unique users by name in eloquent?

Is any way to get the unique users filter by name or email so to not show the users with same email for example in eloquent ?

0 likes
9 replies
bashy's avatar

groupBy() and you're done?

1 like
Vilfago's avatar

You want that the search on name retrieve only one "John" even if you have 10 "John" users ?

Vilfago's avatar

dosent work

Could you be more specific ?

Server has crashed ? You got a 404 error ? The code dropped your users table ?

Vilfago's avatar
})->when($unique_name, function ($query) {
            return $query->>where('first_name',  'like',  '%'.$unique_name.'%')
    ->take(1);
alexMafus's avatar

search to is not in the scope so it dosent work

Vilfago's avatar

Updated with, I guess, the correct variable.

Please or to participate in this conversation.