Support the ongoing development of Laravel.io →
Database Eloquent

So i tried using multiple conditionals on my join but laravel assumes that on join i will be comparing mysql fields and not a constant value. Do I have to wrap this in a raw() method and then escape it using DB::connection()->getPdo()->quote() or are there any shortcuts to this?

->leftJoin('tags', function($join) use ($tags) {
	$join->on('tags.id', '=', 'resource_tag.tag_id');
	$join->on('tags.name', '=', $tags);
})


->leftJoin('tags', function($join) use ($tags) {
	$join->on('tags.id', '=', 'resource_tag.tag_id');
	$join->on('tags.name', '=', DB::raw(DB::connection()->getPdo()->quote($tags)));
})

This seemed to work but seemed a bit much.

Last updated 2 years ago.
0

I had to do this as well a few months ago. I haven't followed up to see if there was a better workaround, but I'll keep my eyes on this thread :) You're not alone.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.