-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Request] Allow other query methods in Eloquent eager loading closure #55
Comments
That's a huge +1 from me. |
+1 |
2 similar comments
👍 |
👍 |
Could be usefull sometimes! +1 |
👍 |
👍 |
3 similar comments
+1 |
+1 |
👍 |
+1 Btw, in the meantime, you can specify these arguments in the relationship if you wish. |
👍 |
3 similar comments
👍 |
👍 |
👍 |
@JonoB would you mind showing us an example of your workaround? |
@falzhobel public function posts()
{
return $this->hasMany('Post')->orderBy('created_at', 'desc');
} And a 👍 |
@falzhobel As @tlgreg demonstrated, you can have any clauses (orderBy, where, etc) in the relationship. Its not workable if you need dynamic clauses, but it works just fine if your clauses are always static. |
Thanks guys :) |
+1 |
What makes you guys think this doesn't already work? It does and always has in Laravel 4. |
💃 |
✌️ |
Now that's just lol. Nice! 🍶 |
I +1'd this without taking the time to try it, but now I have and as @taylorotwell said, it works just like this in Laravel4. We're just a bunch of gullible sheeps ! Haha |
Hahaha, indeed we are just a bunch sheeps. Thanks for the heads up @taylorotwell |
Lol. This really made me laugh. :)) thank you so much @taylorotwell and sorry for opening this feature request :)) |
LoL :D Another Sheep here. thanx @taylorotwell On Sat, Jan 19, 2013 at 5:02 AM, John Kevin M. Basco <
|
Currently, we can only use WHERE clauses in closures when eager loading. Like:
$users = User::with(array('posts' => function($query)
{
$query->where('title', 'like', '%first%');
}))->get();
Maybe allowing ORDERBY, LIMIT, OFFSET etc... will be a good idea? So we will have more control when eager loading something using Eloquent.
Something like:
$users = User::with(array('posts' => function($query)
{
$query->orderBy('created_at', 'desc');
}))->get();
The text was updated successfully, but these errors were encountered: