From e3d9b7eace8aab38261b247bfa2bd11a9683df37 Mon Sep 17 00:00:00 2001
From: Christian <halloei@users.noreply.github.com>
Date: Tue, 4 Jan 2022 20:57:30 +0100
Subject: [PATCH] Fix return type of FromQuery::query() (#3485)

---
 CHANGELOG.md                                             | 2 ++
 src/Concerns/FromQuery.php                               | 4 +++-
 tests/Data/Stubs/FromGroupUsersQueuedQueryExport.php     | 4 +++-
 tests/Data/Stubs/FromNestedArraysQueryExport.php         | 4 +++-
 tests/Data/Stubs/FromNonEloquentQueryExport.php          | 4 +++-
 tests/Data/Stubs/FromQueryWithCustomQuerySize.php        | 4 +++-
 tests/Data/Stubs/FromUsersQueryExport.php                | 4 +++-
 tests/Data/Stubs/FromUsersQueryExportWithEagerLoad.php   | 4 +++-
 tests/Data/Stubs/FromUsersQueryExportWithMapping.php     | 4 +++-
 tests/Data/Stubs/FromUsersQueryExportWithPrepareRows.php | 4 +++-
 10 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d1ca53823..5a1a6765b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
 
 ## [Unreleased]
 
+- Fix return type of `FromQuery::query()`
+
 ## [3.1.35] - 2022-01-04
 
 ### Fixed
diff --git a/src/Concerns/FromQuery.php b/src/Concerns/FromQuery.php
index 923080c5b..f5409aaf7 100644
--- a/src/Concerns/FromQuery.php
+++ b/src/Concerns/FromQuery.php
@@ -2,12 +2,14 @@
 
 namespace Maatwebsite\Excel\Concerns;
 
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Database\Query\Builder;
 
 interface FromQuery
 {
     /**
-     * @return Builder
+     * @return Builder|EloquentBuilder|Relation
      */
     public function query();
 }
diff --git a/tests/Data/Stubs/FromGroupUsersQueuedQueryExport.php b/tests/Data/Stubs/FromGroupUsersQueuedQueryExport.php
index 1de9a97c0..ca06543f2 100644
--- a/tests/Data/Stubs/FromGroupUsersQueuedQueryExport.php
+++ b/tests/Data/Stubs/FromGroupUsersQueuedQueryExport.php
@@ -3,6 +3,8 @@
 namespace Maatwebsite\Excel\Tests\Data\Stubs;
 
 use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Database\Query\Builder;
 use Maatwebsite\Excel\Concerns\Exportable;
 use Maatwebsite\Excel\Concerns\FromQuery;
@@ -15,7 +17,7 @@ class FromGroupUsersQueuedQueryExport implements FromQuery, WithCustomChunkSize,
     use Exportable;
 
     /**
-     * @return Builder
+     * @return Builder|EloquentBuilder|Relation
      */
     public function query()
     {
diff --git a/tests/Data/Stubs/FromNestedArraysQueryExport.php b/tests/Data/Stubs/FromNestedArraysQueryExport.php
index d29892c8f..69b89ad27 100644
--- a/tests/Data/Stubs/FromNestedArraysQueryExport.php
+++ b/tests/Data/Stubs/FromNestedArraysQueryExport.php
@@ -2,6 +2,8 @@
 
 namespace Maatwebsite\Excel\Tests\Data\Stubs;
 
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Database\Query\Builder;
 use Maatwebsite\Excel\Concerns\Exportable;
 use Maatwebsite\Excel\Concerns\FromQuery;
@@ -13,7 +15,7 @@ class FromNestedArraysQueryExport implements FromQuery, WithMapping
     use Exportable;
 
     /**
-     * @return Builder
+     * @return Builder|EloquentBuilder|Relation
      */
     public function query()
     {
diff --git a/tests/Data/Stubs/FromNonEloquentQueryExport.php b/tests/Data/Stubs/FromNonEloquentQueryExport.php
index ceebcdf1e..10902df26 100644
--- a/tests/Data/Stubs/FromNonEloquentQueryExport.php
+++ b/tests/Data/Stubs/FromNonEloquentQueryExport.php
@@ -2,6 +2,8 @@
 
 namespace Maatwebsite\Excel\Tests\Data\Stubs;
 
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Database\Query\Builder;
 use Illuminate\Support\Facades\DB;
 use Maatwebsite\Excel\Concerns\Exportable;
@@ -13,7 +15,7 @@ class FromNonEloquentQueryExport implements FromQuery, WithCustomChunkSize
     use Exportable;
 
     /**
-     * @return Builder
+     * @return Builder|EloquentBuilder|Relation
      */
     public function query()
     {
diff --git a/tests/Data/Stubs/FromQueryWithCustomQuerySize.php b/tests/Data/Stubs/FromQueryWithCustomQuerySize.php
index 8449f516c..a922f6dd9 100644
--- a/tests/Data/Stubs/FromQueryWithCustomQuerySize.php
+++ b/tests/Data/Stubs/FromQueryWithCustomQuerySize.php
@@ -3,6 +3,8 @@
 namespace Maatwebsite\Excel\Tests\Data\Stubs;
 
 use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Database\Query\Builder;
 use Illuminate\Support\Facades\DB;
 use Maatwebsite\Excel\Concerns\Exportable;
@@ -16,7 +18,7 @@ class FromQueryWithCustomQuerySize implements FromQuery, WithCustomQuerySize, Wi
     use Exportable;
 
     /**
-     * @return Builder
+     * @return Builder|EloquentBuilder|Relation
      */
     public function query()
     {
diff --git a/tests/Data/Stubs/FromUsersQueryExport.php b/tests/Data/Stubs/FromUsersQueryExport.php
index 755ae9305..11544872a 100644
--- a/tests/Data/Stubs/FromUsersQueryExport.php
+++ b/tests/Data/Stubs/FromUsersQueryExport.php
@@ -2,6 +2,8 @@
 
 namespace Maatwebsite\Excel\Tests\Data\Stubs;
 
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Database\Query\Builder;
 use Maatwebsite\Excel\Concerns\Exportable;
 use Maatwebsite\Excel\Concerns\FromQuery;
@@ -13,7 +15,7 @@ class FromUsersQueryExport implements FromQuery, WithCustomChunkSize
     use Exportable;
 
     /**
-     * @return Builder
+     * @return Builder|EloquentBuilder|Relation
      */
     public function query()
     {
diff --git a/tests/Data/Stubs/FromUsersQueryExportWithEagerLoad.php b/tests/Data/Stubs/FromUsersQueryExportWithEagerLoad.php
index 57c5c8ede..e290fd9f3 100644
--- a/tests/Data/Stubs/FromUsersQueryExportWithEagerLoad.php
+++ b/tests/Data/Stubs/FromUsersQueryExportWithEagerLoad.php
@@ -2,6 +2,8 @@
 
 namespace Maatwebsite\Excel\Tests\Data\Stubs;
 
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Database\Query\Builder;
 use Maatwebsite\Excel\Concerns\Exportable;
 use Maatwebsite\Excel\Concerns\FromQuery;
@@ -13,7 +15,7 @@ class FromUsersQueryExportWithEagerLoad implements FromQuery, WithMapping
     use Exportable;
 
     /**
-     * @return Builder
+     * @return Builder|EloquentBuilder|Relation
      */
     public function query()
     {
diff --git a/tests/Data/Stubs/FromUsersQueryExportWithMapping.php b/tests/Data/Stubs/FromUsersQueryExportWithMapping.php
index 8b5712e53..d44c2ba99 100644
--- a/tests/Data/Stubs/FromUsersQueryExportWithMapping.php
+++ b/tests/Data/Stubs/FromUsersQueryExportWithMapping.php
@@ -2,6 +2,8 @@
 
 namespace Maatwebsite\Excel\Tests\Data\Stubs;
 
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Database\Query\Builder;
 use Maatwebsite\Excel\Concerns\Exportable;
 use Maatwebsite\Excel\Concerns\FromQuery;
@@ -15,7 +17,7 @@ class FromUsersQueryExportWithMapping implements FromQuery, WithMapping, WithEve
     use Exportable;
 
     /**
-     * @return Builder
+     * @return Builder|EloquentBuilder|Relation
      */
     public function query()
     {
diff --git a/tests/Data/Stubs/FromUsersQueryExportWithPrepareRows.php b/tests/Data/Stubs/FromUsersQueryExportWithPrepareRows.php
index e31ed7909..37411f1aa 100644
--- a/tests/Data/Stubs/FromUsersQueryExportWithPrepareRows.php
+++ b/tests/Data/Stubs/FromUsersQueryExportWithPrepareRows.php
@@ -2,6 +2,8 @@
 
 namespace Maatwebsite\Excel\Tests\Data\Stubs;
 
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Database\Query\Builder;
 use Illuminate\Support\Collection;
 use Maatwebsite\Excel\Concerns\Exportable;
@@ -14,7 +16,7 @@ class FromUsersQueryExportWithPrepareRows implements FromQuery, WithCustomChunkS
     use Exportable;
 
     /**
-     * @return Builder
+     * @return Builder|EloquentBuilder|Relation
      */
     public function query()
     {