Skip to content

Instantly share code, notes, and snippets.

@leocavalcante
Last active December 17, 2015 02:48
Show Gist options
  • Save leocavalcante/5538194 to your computer and use it in GitHub Desktop.
Save leocavalcante/5538194 to your computer and use it in GitHub Desktop.
Laravel 4 - Eager Load Constraints
<?php
Quota::with(
array(
'codes' => function($query) {
$query->where('number', '=', 11);
}
)
)
->where('label', '=', 'foo')
->whereRaw('quotas.count < quotas.limit')
->orderBy('count')
->orderBy('id', 'desc')
->get();
Select *
From quotas as q
Join codes as c
on (c.quotaId = q.id)
Where
q.label = 'foo' and
c.number = 11 and
q.count < q.limit
Order by
q.count asc,
q.id desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment