<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[laravel whereHas with multiple database connections]]></title><description><![CDATA[<p dir="auto">I have small issue with Laravel application , currently I am using two database connection and I want to change the connection in whereHas method.</p>
<p dir="auto">here is my code .</p>
<pre><code>//Relation Ship Methods
public function technician(){
        return $this-&gt;setConnection('common_database')-&gt;belongsTo('App\User', 'technician_id');
    }

    public function commitee(){
        return $this-&gt;setConnection('common_database')-&gt;belongsTo('App\User', 'commitee_validator_id');
    }
</code></pre>
<pre><code>//controller functions 
$practices-&gt;whereHas(‘technician’, function($q) use($search) {
 $q-&gt;where(‘first_name’, 'like', '%' . $search . '%');
});
</code></pre>
]]></description><link>https://lankadevelopers.lk/topic/790/laravel-wherehas-with-multiple-database-connections</link><generator>RSS for Node</generator><lastBuildDate>Mon, 09 Mar 2026 20:48:34 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/790.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 04 Feb 2021 03:40:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to laravel whereHas with multiple database connections on Thu, 04 Feb 2021 14:48:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/27">@root</a> thanks root . let me check it</p>
]]></description><link>https://lankadevelopers.lk/post/4327</link><guid isPermaLink="true">https://lankadevelopers.lk/post/4327</guid><dc:creator><![CDATA[Nubelle]]></dc:creator><pubDate>Thu, 04 Feb 2021 14:48:47 GMT</pubDate></item><item><title><![CDATA[Reply to laravel whereHas with multiple database connections on Thu, 04 Feb 2021 16:11:08 GMT]]></title><description><![CDATA[<p dir="auto">In whereHas you cannot change the database connection, you have to change connection  before where has like this</p>
<pre><code>//get users ids with where
$user_ids = User::where('first_name', 'like', '%' . $search . '%')-&gt;pluck('id');
</code></pre>
<p dir="auto">In User modal you must specify the database connection before above where statement</p>
<pre><code> protected $connection = 'common_database';
</code></pre>
<p dir="auto">Then where in function to find the practices with user ids</p>
<pre><code> $practices-&gt;whereIn('technician_id', $user_ids); 
</code></pre>
]]></description><link>https://lankadevelopers.lk/post/4326</link><guid isPermaLink="true">https://lankadevelopers.lk/post/4326</guid><dc:creator><![CDATA[root]]></dc:creator><pubDate>Thu, 04 Feb 2021 16:11:08 GMT</pubDate></item></channel></rss>