From ff4742c71c58a4941b8738496ba96dabdf5e395b Mon Sep 17 00:00:00 2001 From: Choraimy Kroonstuiver <3661474+axlon@users.noreply.github.com> Date: Mon, 15 Apr 2024 20:49:04 +0200 Subject: [PATCH] [12.x] Make Passport's database connection configurable (#1738) * Make Passport's database connection configurable * formatting --------- Co-authored-by: Taylor Otwell --- config/passport.php | 13 +++++++++++++ src/AuthCode.php | 10 ++++++++++ src/Client.php | 10 ++++++++++ src/PersonalAccessClient.php | 10 ++++++++++ src/RefreshToken.php | 10 ++++++++++ src/Token.php | 10 ++++++++++ 6 files changed, 63 insertions(+) diff --git a/config/passport.php b/config/passport.php index 06053cd12..ae902d80c 100644 --- a/config/passport.php +++ b/config/passport.php @@ -30,6 +30,19 @@ 'public_key' => env('PASSPORT_PUBLIC_KEY'), + /* + |-------------------------------------------------------------------------- + | Passport Database Connection + |-------------------------------------------------------------------------- + | + | By default, Passport's models will utilize your application's default + | database connection. If you wish to use a different connection you + | may specify the configured name of the database connection here. + | + */ + + 'connection' => env('PASSPORT_CONNECTION'), + /* |-------------------------------------------------------------------------- | Client UUIDs diff --git a/src/AuthCode.php b/src/AuthCode.php index 5c045bacb..feda66b42 100644 --- a/src/AuthCode.php +++ b/src/AuthCode.php @@ -60,4 +60,14 @@ public function client() { return $this->belongsTo(Passport::clientModel()); } + + /** + * Get the current connection name for the model. + * + * @return string|null + */ + public function getConnectionName() + { + return $this->connection ?? config('passport.connection'); + } } diff --git a/src/Client.php b/src/Client.php index f77c84af8..16e9dfff4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -228,6 +228,16 @@ public function getIncrementing() return Passport::clientUuids() ? false : $this->incrementing; } + /** + * Get the current connection name for the model. + * + * @return string|null + */ + public function getConnectionName() + { + return $this->connection ?? config('passport.connection'); + } + /** * Create a new factory instance for the model. * diff --git a/src/PersonalAccessClient.php b/src/PersonalAccessClient.php index 171b982ab..2e009c2b3 100644 --- a/src/PersonalAccessClient.php +++ b/src/PersonalAccessClient.php @@ -29,4 +29,14 @@ public function client() { return $this->belongsTo(Passport::clientModel()); } + + /** + * Get the current connection name for the model. + * + * @return string|null + */ + public function getConnectionName() + { + return $this->connection ?? config('passport.connection'); + } } diff --git a/src/RefreshToken.php b/src/RefreshToken.php index df45c4247..cf6a09b56 100644 --- a/src/RefreshToken.php +++ b/src/RefreshToken.php @@ -80,4 +80,14 @@ public function transient() { return false; } + + /** + * Get the current connection name for the model. + * + * @return string|null + */ + public function getConnectionName() + { + return $this->connection ?? config('passport.connection'); + } } diff --git a/src/Token.php b/src/Token.php index ad3f80817..4f9517e61 100644 --- a/src/Token.php +++ b/src/Token.php @@ -126,4 +126,14 @@ public function transient() { return false; } + + /** + * Get the current connection name for the model. + * + * @return string|null + */ + public function getConnectionName() + { + return $this->connection ?? config('passport.connection'); + } }