I'm using Laravel 4.1.
Say cars can be co-owned by many owners. Each owner can own many cars.
If one of the tables is in a totally different database, the whereHas statement doesn't seem to work.
Say a model has a method cars():
MODEL: OWNER
public function cars()
{
return $this->belongsToMany('Car', DB_ONE.'.'.TABLE_PIVOT_CAR_OWNER);
}
MODEL: CAR
protected $connection = 'cars'; //Stored in a different database
public function owners()
{
return $this->belongsToMany('Owner', DB_ONE.'.'.TABLE_PIVOT_CAR_OWNER);
}
_The error say it is trying to find the table in the default database but it's not stored in the default database even though the models are configured correctly._
Example from documentation (assume content exists):
$o = Owner::whereHas('cars', function($q)
{
$q->where('content', 'like', 'foo%');
})->get();
Running queries across connections like that is not supported.
Is this supported now ?
I added package to manage this issue:
Gracias totales @maguilar92 funciona!
Is there a way to do this without an external package?
https://github.com/laravel/framework/issues/24398#issuecomment-511891818
Its works fine for me but both databases should be in the same server
Most helpful comment
I added package to manage this issue:
https://github.com/hoyvoy/laravel-cross-database-subqueries