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

realtebo's avatar

How to create a scope to search by a field of a 1 to n relationship?

Two models, User and Company User hasMany Company (each company has a user_id field)

I need to filter users where 'description' on one of its company is like a specific description.

Is it possible to create a scope of this kind? to be used as ->companyDescriptionLike($user_entered_value)?

0 likes
1 reply

Please or to participate in this conversation.