php - Eloquent - join clause with string value rather than column heading -
i have question regarding join clauses in eloquent, , whether can join on string value rather table column.
i have code below querying nested set joining parent/child records in table 'destinations' via table 'taxonomy'.
the second $join
statement in closure 1 causing issue; eloquent assumes column, when join on t1.parent_type = 'destination'
- ie, t1.parent_type
should = string value, destination
.
$result = db::connection() ->table('destinations d1') ->select(array('d1.title level1', 'd2.title level2')) ->leftjoin('taxonomy t1', function($join) { $join->on('t1.parent_id', '=', 'd1.id'); $join->on('t1.parent_type', '=', 'destination'); }) ->leftjoin('destinations d2', 'd2.id', '=', 't1.child_id') ->where('d1.slug', '=', $slug) ->get();
is possible force eloquent this? i've tried replacing 'destination'
db::raw('destination')
not work either.
thanking kindly.
another best way achieve same :
$result = db::connection() ->table('destinations d1') ->select(array('d1.title level1', 'd2.title level2')) ->leftjoin('taxonomy t1', function($join) { $join->on('t1.parent_id', '=', 'd1.id'); $join->where('t1.parent_type', '=', 'destination'); }) ->leftjoin('destinations d2', 'd2.id', '=', 't1.child_id') ->where('d1.slug', '=', $slug) ->get();
replace on
where
Comments
Post a Comment