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

[5.6] Adding fromSub and fromRaw methods to query Builder #23476

merged 2 commits into from Mar 12, 2018


None yet
2 participants

henriquepedrosa commented Mar 10, 2018


  • fromSub and fromRaw methods to Query Builder so the user can create a subquery on "from", instead of only being able to use table names.


$builder->fromSub(function ($query) {
    $query->select(new Raw('max(last_seen_at) as last_seen_at'))->from('user_sessions')->where('foo', '=', '1');
}, 'sessions')->where('bar', '<', '10');

This creates the following sql:

select * from (select max(last_seen_at) as last_seen_at from "user_sessions" where "foo" = ?) as "sessions" where "bar" < ?

@henriquepedrosa henriquepedrosa changed the title from Adding fromSub and fromRaw methods to query Builder to [5.6] Adding fromSub and fromRaw methods to query Builder Mar 10, 2018

@taylorotwell taylorotwell merged commit b13d5e0 into laravel:5.6 Mar 12, 2018

2 checks passed

continuous-integration/styleci/pr The StyleCI analysis has passed
continuous-integration/travis-ci/pr The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment