Support the ongoing development of Laravel.io →
posted 11 years ago
Database

This Fluent statement:

DB::table('plans')
    ->where('creator_id', '=', '0')
    ->leftJoin('plan_user', function($join){
        $join->on('plan_user.plan_id', '=', 'plans.id')
            ->where('plan_user.user_id', '=', '1');
    })
->get();

Is giving me this query:

select * from plans left join plan_user on plan_user.plan_id = plans.id and plan_user.user_id = '0' where creator_id = '1'

As you can see, it's transposing the values that I'm asking for for user_id and for creator_id. I asked for a user_id of 1 and a creator_id of 0. If I chain the where statement after the leftJoin statement, the values are in the correct place.

This seems like a bug to me. It seems to me that if it can generate the correct query structure with the chained methods in any order, it should be able to match the bound values into the correct places. Any thoughts on this?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

emerson5 emerson5 Joined 22 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.