Repository: laravel/framework
File: src/Illuminate/Database/Eloquent/Factories/Factory.php (PHP)

Code before:
    /**
     * Indicate that related parent models should not be created.
     *
     * @param  array<string|class-string<Model>>  $parents
     * @return static
     */
    public function withoutParents($parents = [])
    {
        return $this->newInstance(! $parents ? ['expandRelationships' => false] : ['excludeRelationships' => $parents]);
    }

    /**
     * Get the name of the database connection that is used to generate models.
     *
     * @return string
     */
    public function getConnectionName()
    {
        return enum_value($this->connection);
    }

    /**
     * Specify the database connection that should be used to generate models.
     *
     * @param  \UnitEnum|string  $connection
     * @return static
     */
    public function connection(\UnitEnum|string $connection)
    {
        return $this->newInstance(['connection' => $connection]);
    }

    /**
     * Create a new instance of the factory builder with the given mutated properties.
     *
     * @param  array  $arguments
     * @return static
     */
    protected function newInstance(array $arguments = [])
    {
        return new static(...array_values(array_merge([
            'count' => $this->count,
            'states' => $this->states,
            'has' => $this->has,
            'for' => $this->for,
            'afterMaking' => $this->afterMaking,
            'afterCreating' => $this->afterCreating,
            'connection' => $this->connection,
            'recycle' => $this->recycle,
            'expandRelationships' => $this->expandRelationships,
            'excludeRelationships' => $this->excludeRelationships,

Review comment (suggestion):
Technically this is backwards incompatible change for classes extending this class and overriding this method with a typed signature, as they would have to update theirs. I'm not sure if such cases are considered to be breaking changes; if so I can port just this change to `master` if preferred.

Code after:

    /**
     * Indicate that related parent models should not be created.
     *
     * @param  array<string|class-string<Model>>  $parents
     * @return static
     */
    public function withoutParents($parents = [])
    {
        return $this->newInstance(! $parents ? ['expandRelationships' => false] : ['excludeRelationships' => $parents]);
    }

    /**
     * Get the name of the database connection that is used to generate models.
     *
     * @return string
     */
    public function getConnectionName()
    {
        return enum_value($this->connection);
    }

    /**
     * Specify the database connection that should be used to generate models.
     *
     * @param  \UnitEnum|string  $connection
     * @return static
     */
    public function connection(UnitEnum|string $connection)
    {
        return $this->newInstance(['connection' => $connection]);
    }

    /**
     * Create a new instance of the factory builder with the given mutated properties.
     *
     * @param  array  $arguments
     * @return static
     */
    protected function newInstance(array $arguments = [])
    {
        return new static(...array_values(array_merge([
            'count' => $this->count,
            'states' => $this->states,
            'has' => $this->has,
            'for' => $this->for,
            'afterMaking' => $this->afterMaking,
            'afterCreating' => $this->afterCreating,
            'connection' => $this->connection,
            'recycle' => $this->recycle,
            'expandRelationships' => $this->expandRelationships,