Home > Software design >  Is there any way to use eloquent addSelect with different database on a different server in Laravel?
Is there any way to use eloquent addSelect with different database on a different server in Laravel?

Time:11-15

A table called api_call_data is being used in a seperate database (done by the original code author, not me) which is located in another server in our Laravel project (I can't move the table).

Due to that, the original query doesn't work anymore. The original query was like below:

$apicallData->addSelect(DB::raw("
    (SELECT MAX(`reg_time`) FROM `api_call_data` as A WHERE `A`.`app_id` = `apps_data`.`app_id` and reg_time between $request->from_date and $request->to_date) as api_reg_time
"))

(I have omitted the rest of the queries after this here)

Is there any way to make this original query work? I really wanted to make this work but I am totally lost here.

CodePudding user response:

You should add another connection on the .env file (or config/database.php, depends on your laravel version) and use that connection in your query. You can refer to this answer for better explaination.

CodePudding user response:

sorry about my poor knowledge about this.
I just found out I cannot use different connections in that way.
I had to change the whole queries to get the data that I need.

  • Related