Skip to content

Commit ea5d9d0

Browse files
committed
set connection telegram
1 parent 0c9aadb commit ea5d9d0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

config/telegram_service.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'name_bot' => 'first_bot',
66
'is_save_database' => env('TELEGRAM_BOT_IS_SAVE_DATABASE', false),
77
'is_technical_job' => env('TELEGRAM_BOT_IS_TECHNICAL_JOB', false),
8+
'db_connection' => env('DB_CONNECTION', 'mysql'),
89
'is_save_files' => false,
910
'is_save_answer' => false,
1011
'path_save_files' => 'storage/telegram/',

src/InteractsTelegramService.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,23 @@ public function telegram($botName = null): MorphOne
3636
}
3737
$botKey = IceTelegram::setInfoBot($infoBot)->hashBotToken();
3838

39-
return $this->morphOne(ServiceTelegram::class, 'owner')->where('bot_key', $botKey);
39+
return $this->setConnection($infoBot['db_connection'] ?? env('DB_CONNECTION'))->morphOne(ServiceTelegram::class, 'owner')->where('bot_key', $botKey);
4040
}
4141

4242
/**
4343
*
4444
* @return MorphMany
4545
*/
46-
public function telegrams(): MorphMany
46+
public function telegrams($botName = null): MorphMany
4747
{
48-
return $this->morphMany(ServiceTelegram::class, 'owner');
48+
if (is_null($botName)) {
49+
$botName = config('telegram_service.default_bot');
50+
$infoBot = config("telegram_service.bots.{$botName}");
51+
} else {
52+
$infoBot = config("telegram_service.bots.{$botName}");
53+
}
54+
55+
return $this->setConnection($infoBot['db_connection'] ?? env('DB_CONNECTION'))->morphMany(ServiceTelegram::class, 'owner');
4956
}
5057

5158
/**
@@ -111,6 +118,6 @@ public function ownerTelegramMessages($botName = null): MorphMany
111118
$infoBot = config("telegram_service.bots.{$botName}");
112119
}
113120
$botKey = IceTelegram::setInfoBot($infoBot)->hashBotToken();
114-
return $this->morphMany(ServiceTelegramOwnerMessage::class, 'owner')->where('bot_key', $botKey);
121+
return $this->setConnection($infoBot['db_connection'] ?? env('DB_CONNECTION'))->morphMany(ServiceTelegramOwnerMessage::class, 'owner')->where('bot_key', $botKey);
115122
}
116123
}

0 commit comments

Comments
 (0)