Small examples

Let's start with a basic scenario, A tenant has N users, each user has a config and a profile:

Image for post
Image for post
  • Query 1:

Bring all users wich have:

user column is_active in config relationship equals true
user column address in profile relationship contains “Foo”
user column tenant_id equals 1

Pure Eloquent:

User::where('tenant_id', 1)
->whereHas('profile', function($q) {
$q->whereRaw('address LIKE %Foo%')
})
->whereHas('config', function($q) {
$q->where('is_active', true);
});

Eloquent Search:

User::search('profile.address', 'contains', "Foo")-search('config.is_active', true)->search('tenant_id', 1)
  • Query 2

Bring a list of user pictures, from a specific tenant, following the conditions:

user column is_active in config equals false
user column created_at must be greater than equal 2000–01–01 or null
Picture is a column in profile

Jmourajn

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store