From 57a35ec43519ef1e7b686f7770c450b9235890cc Mon Sep 17 00:00:00 2001 From: Jonathan Prass Martins Date: Mon, 21 Oct 2024 11:14:36 -0300 Subject: [PATCH] [11.x] Add getConnection() Method to Factory Class for Retrieving Database Connection (#53237) * Add a getter to get the connection of a Factory * Test for getConnection() method inside the Illuminate\Database\Eloquent\Factories\Factory class * return correct type docblock * Update Factory.php * Update DatabaseEloquentFactoryTest.php --------- Co-authored-by: Taylor Otwell --- src/Illuminate/Database/Eloquent/Factories/Factory.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Factories/Factory.php b/src/Illuminate/Database/Eloquent/Factories/Factory.php index 64d64161747..f4b73b4720c 100644 --- a/src/Illuminate/Database/Eloquent/Factories/Factory.php +++ b/src/Illuminate/Database/Eloquent/Factories/Factory.php @@ -728,6 +728,16 @@ public function count(?int $count) return $this->newInstance(['count' => $count]); } + /** + * Get the name of the database connection that is used to generate models. + * + * @return string + */ + public function getConnectionName() + { + return $this->connection; + } + /** * Specify the database connection that should be used to generate models. *