Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

How can i use Laravel Cross database subqueries in different databases? #18

Open
jlopez0313 opened this issue May 29, 2020 · 2 comments

Comments

@jlopez0313
Copy link

jlopez0313 commented May 29, 2020

Is that possible to use Laravel CDS in two different schemas?

I have 2 connections in .env and database.php, but in whereHas it only use the main DB..
p.e.
Users is located in schema 1 from DB A
Posts is located in schema 2 from DB B

I have set the connection in both models and this works fine:

$query = \App\Users->with('Posts')->get();

But this code doesn't work fine:
$query = \App\Users->with('Posts')->whereHas('Posts', function($q) { $q->where('post_type', '3');})->get();

  • Laravel Cross Database Subqueries Version
  • PHP Version: 7.0
  • Database Driver & Version: Postgresql

Description:

Steps To Reproduce:

@MwSpaceLLC
Copy link

Hi there, we want to write that for us all work fine in mysql with package cross-database.

image

In this query User are in DB1 and categories are in DB2. the result work great!

For us, we must specify relation connection ('database.relation') in :

image

And for User, we must replace Authenticatable with new model class:

image

image

Thanks for the trick 👍

@Healyhatman
Copy link

Having trouble with mine on SQL Server, the generated query looks like this

(SQL: select top 1 * from [Clients] where exists (select * from [TMACentral-Demo].[Cli_Core] where [Clients].[CLIENTNUM] = [Cli_Core].[SYSID])

When it should be [TMACentral-Demo].[dbo].[Cli_Core]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants