Skip to content
Advertisement

Laravel – How to query Eloquent relationship?

I have this models in Laravel-5.8:

JavaScript

Then I have this Query in Employee controller function:

JavaScript

How do I include where is_active = 1 from employee_types into the query in Employee:

JavaScript

Advertisement

Answer

You are looking for the whereHas method, querying for the existence of a relationship:

JavaScript

Laravel 5.8 Docs – Eloquent – Relationships – Querying Relationship Existence whereHas

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement