From 4e539a165bcb170f167edb7c4878f95d9a0b7e83 Mon Sep 17 00:00:00 2001 From: Deleu Date: Tue, 3 Dec 2019 10:57:45 -0500 Subject: [PATCH 01/31] Allow developer to preserve query parameters on paginated Api resources --- .../Resources/Json/ResourceCollection.php | 42 ++++++++++++++++-- tests/Integration/Http/ResourceTest.php | 43 +++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Http/Resources/Json/ResourceCollection.php b/src/Illuminate/Http/Resources/Json/ResourceCollection.php index 40f685497950..8245184d386a 100644 --- a/src/Illuminate/Http/Resources/Json/ResourceCollection.php +++ b/src/Illuminate/Http/Resources/Json/ResourceCollection.php @@ -25,6 +25,13 @@ class ResourceCollection extends JsonResource implements Countable, IteratorAggr */ public $collection; + /** + * Determines whether to preserve all query parameters when generating the navigation links. + * + * @var bool + */ + private $queryParameters; + /** * Create a new resource instance. * @@ -38,6 +45,18 @@ public function __construct($resource) $this->resource = $this->collectResource($resource); } + /** + * Preserve all query parameters when generating the navigation links. + * + * @return $this + */ + public function preserveQueryParameters() + { + $this->queryParameters = true; + + return $this; + } + /** * Return the count of items in the resource collection. * @@ -67,8 +86,25 @@ public function toArray($request) */ public function toResponse($request) { - return $this->resource instanceof AbstractPaginator - ? (new PaginatedResourceResponse($this))->toResponse($request) - : parent::toResponse($request); + if ($this->resource instanceof AbstractPaginator) { + return $this->preparePaginatedResponse($request); + } + + return parent::toResponse($request); + } + + /** + * Create an paginate-aware HTTP response. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\JsonResponse + */ + private function preparePaginatedResponse($request) + { + if ($this->queryParameters) { + $this->resource->appends($request->query()); + } + + return (new PaginatedResourceResponse($this))->toResponse($request); } } diff --git a/tests/Integration/Http/ResourceTest.php b/tests/Integration/Http/ResourceTest.php index 6b01b62729d4..96d4e5839ffa 100644 --- a/tests/Integration/Http/ResourceTest.php +++ b/tests/Integration/Http/ResourceTest.php @@ -486,6 +486,49 @@ public function testPaginatorsReceiveLinks() ]); } + public function testPaginatorResourceCanPreserveQueryParameters() + { + Route::get('/', function () { + $collection = collect([new Post(['id' => 2, 'title' => 'Laravel Nova'])]); + $paginator = new LengthAwarePaginator( + $collection, 3, 1, 2 + ); + + return PostCollectionResource::make($paginator)->preserveQueryParameters(); + }); + + $response = $this->withoutExceptionHandling()->get( + '/?framework=laravel&author=Otwell&page=2', ['Accept' => 'application/json'] + ); + + $response->assertStatus(200); + + $response->assertJson([ + 'data' => [ + [ + 'id' => 2, + 'title' => 'Laravel Nova', + ], + ], + 'links' => [ + 'first' => '/?framework=laravel&author=Otwell&page=1', + 'last' => '/?framework=laravel&author=Otwell&page=3', + 'prev' => '/?framework=laravel&author=Otwell&page=1', + 'next' => '/?framework=laravel&author=Otwell&page=3', + ], + 'meta' => [ + 'current_page' => 2, + 'from' => 2, + 'last_page' => 3, + 'path' => '/', + 'per_page' => 1, + 'to' => 2, + 'total' => 3, + ], + ]); + } + + public function testToJsonMayBeLeftOffOfCollection() { Route::get('/', function () { From 01f0486e5e8cf9d518c76b070a0517a98e079b62 Mon Sep 17 00:00:00 2001 From: Deleu Date: Tue, 3 Dec 2019 11:04:10 -0500 Subject: [PATCH 02/31] StyleCI --- tests/Integration/Http/ResourceTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Integration/Http/ResourceTest.php b/tests/Integration/Http/ResourceTest.php index 96d4e5839ffa..aaf08c4e65d8 100644 --- a/tests/Integration/Http/ResourceTest.php +++ b/tests/Integration/Http/ResourceTest.php @@ -528,7 +528,6 @@ public function testPaginatorResourceCanPreserveQueryParameters() ]); } - public function testToJsonMayBeLeftOffOfCollection() { Route::get('/', function () { From 3673354d70b860078d0c88e1d89439e65db9af70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Aur=C3=A9lio=20Deleu?= Date: Tue, 3 Dec 2019 20:30:15 +0100 Subject: [PATCH 03/31] Change method visibility --- src/Illuminate/Http/Resources/Json/ResourceCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Resources/Json/ResourceCollection.php b/src/Illuminate/Http/Resources/Json/ResourceCollection.php index 8245184d386a..65c94ec62f16 100644 --- a/src/Illuminate/Http/Resources/Json/ResourceCollection.php +++ b/src/Illuminate/Http/Resources/Json/ResourceCollection.php @@ -99,7 +99,7 @@ public function toResponse($request) * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\JsonResponse */ - private function preparePaginatedResponse($request) + protected function preparePaginatedResponse($request) { if ($this->queryParameters) { $this->resource->appends($request->query()); From 3f8a842e0c533ea9f09359a7fae55466b851a52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Aur=C3=A9lio=20Deleu?= Date: Thu, 5 Dec 2019 12:08:23 +0100 Subject: [PATCH 04/31] Update src/Illuminate/Http/Resources/Json/ResourceCollection.php Co-Authored-By: Dries Vints --- src/Illuminate/Http/Resources/Json/ResourceCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Resources/Json/ResourceCollection.php b/src/Illuminate/Http/Resources/Json/ResourceCollection.php index 65c94ec62f16..d2c1be6ee5ba 100644 --- a/src/Illuminate/Http/Resources/Json/ResourceCollection.php +++ b/src/Illuminate/Http/Resources/Json/ResourceCollection.php @@ -94,7 +94,7 @@ public function toResponse($request) } /** - * Create an paginate-aware HTTP response. + * Create a paginate-aware HTTP response. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\JsonResponse From 7f0174c4e51a87072908fff2c1db7647a5295e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Aur=C3=A9lio=20Deleu?= Date: Thu, 5 Dec 2019 12:08:29 +0100 Subject: [PATCH 05/31] Update src/Illuminate/Http/Resources/Json/ResourceCollection.php Co-Authored-By: Dries Vints --- src/Illuminate/Http/Resources/Json/ResourceCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Resources/Json/ResourceCollection.php b/src/Illuminate/Http/Resources/Json/ResourceCollection.php index d2c1be6ee5ba..8483285d71f7 100644 --- a/src/Illuminate/Http/Resources/Json/ResourceCollection.php +++ b/src/Illuminate/Http/Resources/Json/ResourceCollection.php @@ -96,7 +96,7 @@ public function toResponse($request) /** * Create a paginate-aware HTTP response. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\JsonResponse */ protected function preparePaginatedResponse($request) From 43cf1db50987e4dcac7e2da3a65b860ad2403031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Aur=C3=A9lio=20Deleu?= Date: Thu, 5 Dec 2019 12:08:36 +0100 Subject: [PATCH 06/31] Update src/Illuminate/Http/Resources/Json/ResourceCollection.php Co-Authored-By: Dries Vints --- src/Illuminate/Http/Resources/Json/ResourceCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Resources/Json/ResourceCollection.php b/src/Illuminate/Http/Resources/Json/ResourceCollection.php index 8483285d71f7..deab912f16cb 100644 --- a/src/Illuminate/Http/Resources/Json/ResourceCollection.php +++ b/src/Illuminate/Http/Resources/Json/ResourceCollection.php @@ -30,7 +30,7 @@ class ResourceCollection extends JsonResource implements Countable, IteratorAggr * * @var bool */ - private $queryParameters; + protected $queryParameters; /** * Create a new resource instance. From e92a70800671187cc30a39e965144101d5db169a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 5 Dec 2019 08:19:51 -0600 Subject: [PATCH 07/31] formatting and improvements --- .../Resources/Json/ResourceCollection.php | 32 +++++++++++--- tests/Integration/Http/ResourceTest.php | 44 ++++++++++++++++++- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Http/Resources/Json/ResourceCollection.php b/src/Illuminate/Http/Resources/Json/ResourceCollection.php index deab912f16cb..d5fbe2b5e224 100644 --- a/src/Illuminate/Http/Resources/Json/ResourceCollection.php +++ b/src/Illuminate/Http/Resources/Json/ResourceCollection.php @@ -26,10 +26,17 @@ class ResourceCollection extends JsonResource implements Countable, IteratorAggr public $collection; /** - * Determines whether to preserve all query parameters when generating the navigation links. + * Indicates if all existing request query parameters should be added to pagination links. * * @var bool */ + protected $preserveAllQueryParameters = false; + + /** + * The query parameters that should be added to the pagination links. + * + * @var array + */ protected $queryParameters; /** @@ -46,13 +53,26 @@ public function __construct($resource) } /** - * Preserve all query parameters when generating the navigation links. + * Indicate that all current query parameters should be appended to pagination links. + */ + public function preserveQuery() + { + $this->preserveAllQueryParameters = true; + + return $this; + } + + /** + * Preserve the given (or all) query parameters when generating the pagination links. * + * @param array $query * @return $this */ - public function preserveQueryParameters() + public function withQuery(array $query) { - $this->queryParameters = true; + $this->preserveAllQueryParameters = false; + + $this->queryParameters = $query; return $this; } @@ -101,8 +121,10 @@ public function toResponse($request) */ protected function preparePaginatedResponse($request) { - if ($this->queryParameters) { + if ($this->preserveAllQueryParameters) { $this->resource->appends($request->query()); + } elseif (! is_null($this->queryParameters)) { + $this->resource->appends($this->queryParameters); } return (new PaginatedResourceResponse($this))->toResponse($request); diff --git a/tests/Integration/Http/ResourceTest.php b/tests/Integration/Http/ResourceTest.php index aaf08c4e65d8..8136c6d7eb07 100644 --- a/tests/Integration/Http/ResourceTest.php +++ b/tests/Integration/Http/ResourceTest.php @@ -494,7 +494,7 @@ public function testPaginatorResourceCanPreserveQueryParameters() $collection, 3, 1, 2 ); - return PostCollectionResource::make($paginator)->preserveQueryParameters(); + return PostCollectionResource::make($paginator)->preserveQuery(); }); $response = $this->withoutExceptionHandling()->get( @@ -528,6 +528,48 @@ public function testPaginatorResourceCanPreserveQueryParameters() ]); } + public function testPaginatorResourceCanReceiveQueryParameters() + { + Route::get('/', function () { + $collection = collect([new Post(['id' => 2, 'title' => 'Laravel Nova'])]); + $paginator = new LengthAwarePaginator( + $collection, 3, 1, 2 + ); + + return PostCollectionResource::make($paginator)->withQuery(['author' => 'Taylor']); + }); + + $response = $this->withoutExceptionHandling()->get( + '/?framework=laravel&author=Otwell&page=2', ['Accept' => 'application/json'] + ); + + $response->assertStatus(200); + + $response->assertJson([ + 'data' => [ + [ + 'id' => 2, + 'title' => 'Laravel Nova', + ], + ], + 'links' => [ + 'first' => '/?author=Taylor&page=1', + 'last' => '/?author=Taylor&page=3', + 'prev' => '/?author=Taylor&page=1', + 'next' => '/?author=Taylor&page=3', + ], + 'meta' => [ + 'current_page' => 2, + 'from' => 2, + 'last_page' => 3, + 'path' => '/', + 'per_page' => 1, + 'to' => 2, + 'total' => 3, + ], + ]); + } + public function testToJsonMayBeLeftOffOfCollection() { Route::get('/', function () { From 9142e5e271786a8336d00c7ebe28f96e0ea4df10 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 5 Dec 2019 08:20:25 -0600 Subject: [PATCH 08/31] Fix comment --- src/Illuminate/Http/Resources/Json/ResourceCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Resources/Json/ResourceCollection.php b/src/Illuminate/Http/Resources/Json/ResourceCollection.php index d5fbe2b5e224..012a5504ed05 100644 --- a/src/Illuminate/Http/Resources/Json/ResourceCollection.php +++ b/src/Illuminate/Http/Resources/Json/ResourceCollection.php @@ -63,7 +63,7 @@ public function preserveQuery() } /** - * Preserve the given (or all) query parameters when generating the pagination links. + * Preserve the given query parameters when generating the pagination links. * * @param array $query * @return $this From f8e15047ef7ea160e2284369c035e79ac963a28e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 5 Dec 2019 08:20:57 -0600 Subject: [PATCH 09/31] fix comment --- src/Illuminate/Http/Resources/Json/ResourceCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Resources/Json/ResourceCollection.php b/src/Illuminate/Http/Resources/Json/ResourceCollection.php index 012a5504ed05..5f44a6fbb2ed 100644 --- a/src/Illuminate/Http/Resources/Json/ResourceCollection.php +++ b/src/Illuminate/Http/Resources/Json/ResourceCollection.php @@ -63,7 +63,7 @@ public function preserveQuery() } /** - * Preserve the given query parameters when generating the pagination links. + * Specify the query string parameters that should be present on pagination links. * * @param array $query * @return $this From 11f410a3439f47efb60f19cf100e719e461fd75b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 5 Dec 2019 08:21:47 -0600 Subject: [PATCH 10/31] add doc block return --- src/Illuminate/Http/Resources/Json/ResourceCollection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Illuminate/Http/Resources/Json/ResourceCollection.php b/src/Illuminate/Http/Resources/Json/ResourceCollection.php index 5f44a6fbb2ed..f71fd0b3fc02 100644 --- a/src/Illuminate/Http/Resources/Json/ResourceCollection.php +++ b/src/Illuminate/Http/Resources/Json/ResourceCollection.php @@ -54,6 +54,8 @@ public function __construct($resource) /** * Indicate that all current query parameters should be appended to pagination links. + * + * @return $this */ public function preserveQuery() { From 874c4f6135a4c23d5c3040aa020b84aaaa41a3ca Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Thu, 5 Dec 2019 23:04:41 +0200 Subject: [PATCH 11/31] [6.x] update changelog --- CHANGELOG-6.x.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-6.x.md b/CHANGELOG-6.x.md index 00be2945f81a..066a8faca445 100644 --- a/CHANGELOG-6.x.md +++ b/CHANGELOG-6.x.md @@ -1,9 +1,22 @@ # Release Notes for 6.x -## [Unreleased](https://github.com/laravel/framework/compare/v6.6.1...6.x) +## [Unreleased](https://github.com/laravel/framework/compare/v6.6.2...6.x) ### TODO -- Support retryAfter Option on Queued Listeners ([#30743](https://github.com/laravel/framework/pull/30743)) +- Added `ResourceCollection::preserveQueryParameters()` for preserve query parameters on paginated api resources ([#30745](https://github.com/laravel/framework/pull/30745), [e92a708](https://github.com/laravel/framework/commit/e92a70800671187cc30a39e965144101d5db169a)) + + +## [v6.6.2 (2019-12-05)](https://github.com/laravel/framework/compare/v6.6.1...v6.6.2) + +### Added +- Added `Illuminate\Support\Facades\Facade::partialMock()` method ([#30754](https://github.com/laravel/framework/pull/30754)) +- Added of support `retryAfter` option on queued listeners ([#30743](https://github.com/laravel/framework/pull/30743)) + +### Fixed +- Fixed zero parameter for routes ([#30768](https://github.com/laravel/framework/pull/30768)) + +### Changed +- Changed `getAllViews()` method visibility from `protected` to `public` in all schema builders ([#30757](https://github.com/laravel/framework/pull/30757)) ## [v6.6.1 (2019-12-03)](https://github.com/laravel/framework/compare/v6.6.0...v6.6.1) From 9abc0896070176fd6987d95f0d1b50de947db82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20D=2E=20Nagy?= Date: Fri, 6 Dec 2019 14:40:59 +0100 Subject: [PATCH 12/31] add missing docblock @return tags (#30772) --- src/Illuminate/Contracts/Cookie/QueueingFactory.php | 1 + src/Illuminate/Database/Concerns/ManagesTransactions.php | 1 + src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php | 2 ++ src/Illuminate/Database/Schema/PostgresBuilder.php | 2 ++ .../Foundation/Providers/FoundationServiceProvider.php | 2 ++ src/Illuminate/Http/ResponseTrait.php | 2 ++ src/Illuminate/Notifications/DatabaseNotification.php | 2 ++ src/Illuminate/Queue/Worker.php | 1 + src/Illuminate/Support/DateFactory.php | 1 + src/Illuminate/Support/Env.php | 4 ++-- 10 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Contracts/Cookie/QueueingFactory.php b/src/Illuminate/Contracts/Cookie/QueueingFactory.php index 96bf87139575..d6c74b8f9545 100644 --- a/src/Illuminate/Contracts/Cookie/QueueingFactory.php +++ b/src/Illuminate/Contracts/Cookie/QueueingFactory.php @@ -17,6 +17,7 @@ public function queue(...$parameters); * * @param string $name * @param string|null $path + * @return void */ public function unqueue($name, $path = null); diff --git a/src/Illuminate/Database/Concerns/ManagesTransactions.php b/src/Illuminate/Database/Concerns/ManagesTransactions.php index dee9626cd540..b7ca34a474b5 100644 --- a/src/Illuminate/Database/Concerns/ManagesTransactions.php +++ b/src/Illuminate/Database/Concerns/ManagesTransactions.php @@ -256,6 +256,7 @@ protected function performRollBack($toLevel) * Handle an exception from a rollback. * * @param \Exception $e + * @return void * * @throws \Exception */ diff --git a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php index 726803b06aa0..32af161c66b3 100755 --- a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php @@ -179,6 +179,7 @@ public function compileIndex(Blueprint $blueprint, Fluent $command) * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $command + * @return void * * @throws \RuntimeException */ @@ -309,6 +310,7 @@ public function compileDropIndex(Blueprint $blueprint, Fluent $command) * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $command + * @return void * * @throws \RuntimeException */ diff --git a/src/Illuminate/Database/Schema/PostgresBuilder.php b/src/Illuminate/Database/Schema/PostgresBuilder.php index 9c78f4294548..76673a719a41 100755 --- a/src/Illuminate/Database/Schema/PostgresBuilder.php +++ b/src/Illuminate/Database/Schema/PostgresBuilder.php @@ -77,6 +77,8 @@ public function dropAllViews() /** * Drop all types from the database. + * + * @return void */ public function dropAllTypes() { diff --git a/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php b/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php index f1b994c2daed..d005c3615bab 100644 --- a/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php @@ -19,6 +19,8 @@ class FoundationServiceProvider extends AggregateServiceProvider /** * Boot the service provider. + * + * @return void */ public function boot() { diff --git a/src/Illuminate/Http/ResponseTrait.php b/src/Illuminate/Http/ResponseTrait.php index 42379247ba5d..76744b487fb8 100644 --- a/src/Illuminate/Http/ResponseTrait.php +++ b/src/Illuminate/Http/ResponseTrait.php @@ -142,6 +142,8 @@ public function withException(Exception $e) /** * Throws the response in a HttpResponseException instance. * + * @return void + * * @throws \Illuminate\Http\Exceptions\HttpResponseException */ public function throwResponse() diff --git a/src/Illuminate/Notifications/DatabaseNotification.php b/src/Illuminate/Notifications/DatabaseNotification.php index 1c1b6bbedad2..ab53df22335f 100644 --- a/src/Illuminate/Notifications/DatabaseNotification.php +++ b/src/Illuminate/Notifications/DatabaseNotification.php @@ -39,6 +39,8 @@ class DatabaseNotification extends Model /** * Get the notifiable entity that the notification belongs to. + * + * @return \Illuminate\Database\Eloquent\Relations\MorphTo */ public function notifiable() { diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 91a4773f0a95..37296c0a2040 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -217,6 +217,7 @@ protected function pauseWorker(WorkerOptions $options, $lastRestart) * @param \Illuminate\Queue\WorkerOptions $options * @param int $lastRestart * @param mixed $job + * @return void */ protected function stopIfNecessary(WorkerOptions $options, $lastRestart, $job = null) { diff --git a/src/Illuminate/Support/DateFactory.php b/src/Illuminate/Support/DateFactory.php index cb679c745309..72f22231dbf0 100644 --- a/src/Illuminate/Support/DateFactory.php +++ b/src/Illuminate/Support/DateFactory.php @@ -115,6 +115,7 @@ class DateFactory * Use the given handler when generating dates (class name, callable, or factory). * * @param mixed $handler + * @return mixed * * @throws \InvalidArgumentException */ diff --git a/src/Illuminate/Support/Env.php b/src/Illuminate/Support/Env.php index a019fb86b0e5..751e53845f65 100644 --- a/src/Illuminate/Support/Env.php +++ b/src/Illuminate/Support/Env.php @@ -34,7 +34,7 @@ class Env /** * Enable the putenv adapter. * - * @var bool + * @return void */ public static function enablePutenv() { @@ -46,7 +46,7 @@ public static function enablePutenv() /** * Disable the putenv adapter. * - * @var bool + * @return void */ public static function disablePutenv() { From e30a0c979d98f2f1f7b6c565e4002734237a280b Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 6 Dec 2019 16:51:10 +0100 Subject: [PATCH 13/31] Update unit test stub --- src/Illuminate/Foundation/Console/stubs/unit-test.stub | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Console/stubs/unit-test.stub b/src/Illuminate/Foundation/Console/stubs/unit-test.stub index 87a9ec40d756..4eb7c4a91ee7 100644 --- a/src/Illuminate/Foundation/Console/stubs/unit-test.stub +++ b/src/Illuminate/Foundation/Console/stubs/unit-test.stub @@ -2,9 +2,7 @@ namespace DummyNamespace; -use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Foundation\Testing\WithFaker; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class DummyClass extends TestCase { From 4e6784b0e0fd163a45a53e54dc7919ac49fff648 Mon Sep 17 00:00:00 2001 From: Gege Date: Fri, 6 Dec 2019 17:31:14 +0100 Subject: [PATCH 14/31] Fix missed docblock formatting --- src/Illuminate/Database/Concerns/ManagesTransactions.php | 2 +- src/Illuminate/Queue/Worker.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Concerns/ManagesTransactions.php b/src/Illuminate/Database/Concerns/ManagesTransactions.php index b7ca34a474b5..39aa7849b73e 100644 --- a/src/Illuminate/Database/Concerns/ManagesTransactions.php +++ b/src/Illuminate/Database/Concerns/ManagesTransactions.php @@ -255,7 +255,7 @@ protected function performRollBack($toLevel) /** * Handle an exception from a rollback. * - * @param \Exception $e + * @param \Exception $e * @return void * * @throws \Exception diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 37296c0a2040..9c3de7676c09 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -52,7 +52,7 @@ class Worker /** * The callback used to determine if the application is in maintenance mode. * - * @var \callable + * @var callable */ protected $isDownForMaintenance; @@ -76,7 +76,7 @@ class Worker * @param \Illuminate\Contracts\Queue\Factory $manager * @param \Illuminate\Contracts\Events\Dispatcher $events * @param \Illuminate\Contracts\Debug\ExceptionHandler $exceptions - * @param \callable $isDownForMaintenance + * @param callable $isDownForMaintenance * @return void */ public function __construct(QueueManager $manager, From 9705cdf7cad0815bb6117ab256485ee745ce87b2 Mon Sep 17 00:00:00 2001 From: Gege Date: Fri, 6 Dec 2019 17:38:15 +0100 Subject: [PATCH 15/31] format docs --- src/Illuminate/Console/GeneratorCommand.php | 2 ++ src/Illuminate/Foundation/Auth/VerifiesEmails.php | 1 + src/Illuminate/Support/helpers.php | 1 + 3 files changed, 4 insertions(+) diff --git a/src/Illuminate/Console/GeneratorCommand.php b/src/Illuminate/Console/GeneratorCommand.php index 743f4eaeebbf..d6e4b5ba2913 100644 --- a/src/Illuminate/Console/GeneratorCommand.php +++ b/src/Illuminate/Console/GeneratorCommand.php @@ -46,6 +46,7 @@ abstract protected function getStub(); * Execute the console command. * * @return bool|null + * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function handle() @@ -153,6 +154,7 @@ protected function makeDirectory($path) * * @param string $name * @return string + * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ protected function buildClass($name) diff --git a/src/Illuminate/Foundation/Auth/VerifiesEmails.php b/src/Illuminate/Foundation/Auth/VerifiesEmails.php index abd8b4d8a57c..88a19f07e703 100644 --- a/src/Illuminate/Foundation/Auth/VerifiesEmails.php +++ b/src/Illuminate/Foundation/Auth/VerifiesEmails.php @@ -28,6 +28,7 @@ public function show(Request $request) * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response + * * @throws \Illuminate\Auth\Access\AuthorizationException */ public function verify(Request $request) diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 89b955bb33fe..d968dba5466d 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -454,6 +454,7 @@ function throw_if($condition, $exception, ...$parameters) * @param \Throwable|string $exception * @param array ...$parameters * @return mixed + * * @throws \Throwable */ function throw_unless($condition, $exception, ...$parameters) From 483481519adca80b4f58617940c1b00fbf1696a0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 6 Dec 2019 10:56:13 -0600 Subject: [PATCH 16/31] [6.x] Reconnect on connection missing to recover horizon (#30778) * reconnect on connection missing to recover horizon * add property --- .../Redis/Connections/PhpRedisConnection.php | 33 ++++++++++++++++++- .../Redis/Connectors/PhpRedisConnector.php | 10 ++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 4b2079355933..d03fd755d1ad 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -4,23 +4,34 @@ use Closure; use Illuminate\Contracts\Redis\Connection as ConnectionContract; +use Illuminate\Support\Str; use Redis; use RedisCluster; +use RedisException; /** * @mixin \Redis */ class PhpRedisConnection extends Connection implements ConnectionContract { + /** + * The connection creation callback. + * + * @var callable + */ + protected $connector; + /** * Create a new PhpRedis connection. * * @param \Redis $client + * @param callable $connector * @return void */ - public function __construct($client) + public function __construct($client, callable $connector = null) { $this->client = $client; + $this->connector = $connector; } /** @@ -416,6 +427,26 @@ public function executeRaw(array $parameters) return $this->command('rawCommand', $parameters); } + /** + * Run a command against the Redis database. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function command($method, array $parameters = []) + { + try { + return parent::command($method, $parameters); + } catch (RedisException $e) { + if (Str::contains($e->getMessage(), 'went away')) { + $this->client = $this->connector ? call_user_func($this->connector) : $this->client; + } + + throw $e; + } + } + /** * Disconnects from the Redis instance. * diff --git a/src/Illuminate/Redis/Connectors/PhpRedisConnector.php b/src/Illuminate/Redis/Connectors/PhpRedisConnector.php index 11bae6c17cca..743568a5adc4 100644 --- a/src/Illuminate/Redis/Connectors/PhpRedisConnector.php +++ b/src/Illuminate/Redis/Connectors/PhpRedisConnector.php @@ -22,9 +22,13 @@ class PhpRedisConnector implements Connector */ public function connect(array $config, array $options) { - return new PhpRedisConnection($this->createClient(array_merge( - $config, $options, Arr::pull($config, 'options', []) - ))); + $connector = function () use ($config, $options) { + return $this->createClient(array_merge( + $config, $options, Arr::pull($config, 'options', []) + )); + }; + + return new PhpRedisConnection($connector(), $connector); } /** From e0ce10f413281c399d4976735019ce43745be0c5 Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Sun, 8 Dec 2019 00:23:29 +0200 Subject: [PATCH 17/31] [6.x] update changelog --- CHANGELOG-6.x.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-6.x.md b/CHANGELOG-6.x.md index 066a8faca445..726945f9bb48 100644 --- a/CHANGELOG-6.x.md +++ b/CHANGELOG-6.x.md @@ -4,6 +4,7 @@ ### TODO - Added `ResourceCollection::preserveQueryParameters()` for preserve query parameters on paginated api resources ([#30745](https://github.com/laravel/framework/pull/30745), [e92a708](https://github.com/laravel/framework/commit/e92a70800671187cc30a39e965144101d5db169a)) +- Reconnect on connection missing to recover horizon ([#30778](https://github.com/laravel/framework/pull/30778)) ## [v6.6.2 (2019-12-05)](https://github.com/laravel/framework/compare/v6.6.1...v6.6.2) From 79c2c3862f0a37f6dcdf1c4fcb0427a4a0b7ed14 Mon Sep 17 00:00:00 2001 From: Zing Date: Mon, 9 Dec 2019 21:53:22 +0800 Subject: [PATCH 18/31] add method to get qualified timestamps column (#30792) --- .../Eloquent/Concerns/HasTimestamps.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php b/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php index 3f0fa4e26326..8de099c998cd 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php @@ -126,4 +126,24 @@ public function getUpdatedAtColumn() { return static::UPDATED_AT; } + + /** + * Get the fully qualified "created at" column. + * + * @return string + */ + public function getQualifiedCreatedAtColumn() + { + return $this->qualifyColumn($this->getCreatedAtColumn()); + } + + /** + * Get the fully qualified "updated at" column. + * + * @return string + */ + public function getQualifiedUpdatedAtColumn() + { + return $this->qualifyColumn($this->getUpdatedAtColumn()); + } } From 5728c66b0a444086a34b5bc1fe5ac866251fab90 Mon Sep 17 00:00:00 2001 From: James Dickens Date: Tue, 10 Dec 2019 00:56:07 +1100 Subject: [PATCH 19/31] [6.x] Fix explicit models in string-based database validation rules (#30790) * Fix table parsing when validation rules are passed as strings * Add tests for parsing tables * Update tests to ensure backwards compatibility with connection specification --- .../Concerns/ValidatesAttributes.php | 13 +++++- tests/Validation/ValidationValidatorTest.php | 44 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index e6c6b9817ba8..eba3599c8d42 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -13,6 +13,7 @@ use Egulias\EmailValidator\Validation\RFCValidation; use Egulias\EmailValidator\Validation\SpoofCheckValidation; use Exception; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Date; @@ -815,7 +816,17 @@ protected function getUniqueExtra($parameters) */ public function parseTable($table) { - return Str::contains($table, '.') ? explode('.', $table, 2) : [null, $table]; + [$connection, $table] = Str::contains($table, '.') ? explode('.', $table, 2) : [null, $table]; + + if (Str::contains($table, '\\') && class_exists($table)) { + $model = new $table; + + if ($model instanceof Model) { + $table = $model->getTable(); + } + } + + return [$connection, $table]; } /** diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 4ab6a9e0bb26..6d309750a480 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -11,6 +11,7 @@ use Illuminate\Contracts\Translation\Translator as TranslatorContract; use Illuminate\Contracts\Validation\ImplicitRule; use Illuminate\Contracts\Validation\Rule; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; use Illuminate\Support\Carbon; use Illuminate\Translation\ArrayLoader; @@ -4293,6 +4294,36 @@ public function testExtractDataFromPath() $this->assertEquals(['cat' => ['cat1' => ['name' => '1']]], ValidationData::extractDataFromPath('cat.cat1.name', $data)); } + public function testParsingTablesFromModels() + { + $trans = $this->getIlluminateArrayTranslator(); + $v = new Validator($trans, [], []); + + $implicit_no_connection = $v->parseTable(ImplicitTableModel::class); + $this->assertEquals(null, $implicit_no_connection[0]); + $this->assertEquals('implicit_table_models', $implicit_no_connection[1]); + + $explicit_no_connection = $v->parseTable(ExplicitTableModel::class); + $this->assertEquals(null, $explicit_no_connection[0]); + $this->assertEquals('explicits', $explicit_no_connection[1]); + + $raw_no_connection = $v->parseTable('table'); + $this->assertEquals(null, $raw_no_connection[0]); + $this->assertEquals('table', $raw_no_connection[1]); + + $implicit_connection = $v->parseTable('connection.'.ImplicitTableModel::class); + $this->assertEquals('connection', $implicit_connection[0]); + $this->assertEquals('implicit_table_models', $implicit_connection[1]); + + $explicit_connection = $v->parseTable('connection.'.ExplicitTableModel::class); + $this->assertEquals('connection', $explicit_connection[0]); + $this->assertEquals('explicits', $explicit_connection[1]); + + $raw_connection = $v->parseTable('connection.table'); + $this->assertEquals('connection', $raw_connection[0]); + $this->assertEquals('table', $raw_connection[1]); + } + public function testUsingSettersWithImplicitRules() { $trans = $this->getIlluminateArrayTranslator(); @@ -4755,3 +4786,16 @@ public function getIlluminateArrayTranslator() ); } } + +class ImplicitTableModel extends Model +{ + protected $guarded = []; + public $timestamps = false; +} + +class ExplicitTableModel extends Model +{ + protected $table = 'explicits'; + protected $guarded = []; + public $timestamps = false; +} From 58d5f788dc47b63bc861417fbf9f7bdfff1b0428 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 9 Dec 2019 15:18:30 +0100 Subject: [PATCH 20/31] Update travis file --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 49291a4d90e0..f6c306ae7911 100755 --- a/.travis.yml +++ b/.travis.yml @@ -39,4 +39,5 @@ install: - if [[ $SETUP = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi - if [[ $SETUP = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi -script: vendor/bin/phpunit +script: + - vendor/bin/phpunit From ff807cccf23427919e7d5fdcc8a4326ef5cc7b31 Mon Sep 17 00:00:00 2001 From: clem Date: Mon, 9 Dec 2019 21:49:57 +0700 Subject: [PATCH 21/31] replace collection pop() with get() accessor (#30783) --- src/Illuminate/Routing/RedirectController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Routing/RedirectController.php b/src/Illuminate/Routing/RedirectController.php index a1a35a34e4d1..e98414ba84ac 100644 --- a/src/Illuminate/Routing/RedirectController.php +++ b/src/Illuminate/Routing/RedirectController.php @@ -19,9 +19,11 @@ public function __invoke(Request $request, UrlGenerator $url) { $parameters = collect($request->route()->parameters()); - $status = $parameters->pop(); + $status = $parameters->get('status'); - $destination = $parameters->pop(); + $destination = $parameters->get('destination'); + + $parameters->forget('status')->forget('destination'); $route = (new Route('GET', $destination, [ 'as' => 'laravel_route_redirect_destination', From 0b4134274078a03bdc65493475cb0ffa761e6770 Mon Sep 17 00:00:00 2001 From: Abdel Elrafa Date: Mon, 9 Dec 2019 10:00:05 -0500 Subject: [PATCH 22/31] Add the exceptionContext method to the exception handler to allow exception specific data to be added to the logging context. (#30780) --- .../Foundation/Exceptions/Handler.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 694c87f11e47..231966ab94ea 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -115,8 +115,12 @@ public function report(Exception $e) $logger->error( $e->getMessage(), - array_merge($this->context(), ['exception' => $e] - )); + array_merge( + $this->exceptionContext($e), + $this->context(), + ['exception' => $e] + ) + ); } /** @@ -145,6 +149,17 @@ protected function shouldntReport(Exception $e) })); } + /** + * Get the default exception context variables for logging. + * + * @param \Exception $e + * @return array + */ + protected function exceptionContext(Exception $e) + { + return []; + } + /** * Get the default context variables for logging. * From c5c5b75a07af4442c437d8730ad0ecec8a5b97cc Mon Sep 17 00:00:00 2001 From: Josias Montag Date: Tue, 10 Dec 2019 03:17:51 +0100 Subject: [PATCH 23/31] Improve ShouldBroadcastNow performance --- src/Illuminate/Broadcasting/BroadcastManager.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index 46b85817823c..975ca6e1fca6 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -9,6 +9,7 @@ use Illuminate\Broadcasting\Broadcasters\RedisBroadcaster; use Illuminate\Contracts\Broadcasting\Factory as FactoryContract; use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Bus\Dispatcher as BusDispatcherContract; use InvalidArgumentException; use Psr\Log\LoggerInterface; use Pusher\Pusher; @@ -108,10 +109,8 @@ public function event($event = null) */ public function queue($event) { - $connection = $event instanceof ShouldBroadcastNow ? 'sync' : null; - - if (is_null($connection) && isset($event->connection)) { - $connection = $event->connection; + if ($event instanceof ShouldBroadcastNow) { + return $this->app->make(BusDispatcherContract::class)->dispatchNow(new BroadcastEvent(clone $event)); } $queue = null; @@ -124,7 +123,7 @@ public function queue($event) $queue = $event->queue; } - $this->app->make('queue')->connection($connection)->pushOn( + $this->app->make('queue')->connection($event->connection ?? null)->pushOn( $queue, new BroadcastEvent(clone $event) ); } From 7e857b6ffe2cc5a914e61675170cc671be985f66 Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 10 Dec 2019 09:45:09 +0100 Subject: [PATCH 24/31] Added ability for postmark transport to throw errors. --- src/Illuminate/Mail/TransportManager.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Mail/TransportManager.php b/src/Illuminate/Mail/TransportManager.php index 3d73833736e6..8a84e1865df3 100644 --- a/src/Illuminate/Mail/TransportManager.php +++ b/src/Illuminate/Mail/TransportManager.php @@ -12,6 +12,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Manager; use Postmark\Transport as PostmarkTransport; +use Postmark\ThrowExceptionOnFailurePlugin; use Psr\Log\LoggerInterface; use Swift_SendmailTransport as SendmailTransport; use Swift_SmtpTransport as SmtpTransport; @@ -148,9 +149,13 @@ protected function createMailgunDriver() */ protected function createPostmarkDriver() { - return new PostmarkTransport( + $transport = new PostmarkTransport( $this->config->get('services.postmark.token') ); + + $transport->registerPlugin(new ThrowExceptionOnFailurePlugin()); + + return $transport; } /** From 47d936bdbfccc6be36c461ec3d5fd216c62595b1 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 10 Dec 2019 10:12:31 +0100 Subject: [PATCH 25/31] Update TransportManager.php --- src/Illuminate/Mail/TransportManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Mail/TransportManager.php b/src/Illuminate/Mail/TransportManager.php index 8a84e1865df3..5948b6c2c2bf 100644 --- a/src/Illuminate/Mail/TransportManager.php +++ b/src/Illuminate/Mail/TransportManager.php @@ -11,8 +11,8 @@ use Illuminate\Mail\Transport\SesTransport; use Illuminate\Support\Arr; use Illuminate\Support\Manager; -use Postmark\Transport as PostmarkTransport; use Postmark\ThrowExceptionOnFailurePlugin; +use Postmark\Transport as PostmarkTransport; use Psr\Log\LoggerInterface; use Swift_SendmailTransport as SendmailTransport; use Swift_SmtpTransport as SmtpTransport; From 4320b82f848d63d41df95860ed3bf595202873a9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 10 Dec 2019 07:57:06 -0600 Subject: [PATCH 26/31] formatting --- src/Illuminate/Mail/TransportManager.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Mail/TransportManager.php b/src/Illuminate/Mail/TransportManager.php index 5948b6c2c2bf..e711bc5d7e63 100644 --- a/src/Illuminate/Mail/TransportManager.php +++ b/src/Illuminate/Mail/TransportManager.php @@ -149,13 +149,11 @@ protected function createMailgunDriver() */ protected function createPostmarkDriver() { - $transport = new PostmarkTransport( + return tap(new PostmarkTransport( $this->config->get('services.postmark.token') - ); - - $transport->registerPlugin(new ThrowExceptionOnFailurePlugin()); - - return $transport; + ), function ($transport) { + $transport->registerPlugin(new ThrowExceptionOnFailurePlugin()); + }); } /** From 5b3cc9752d873be96ac34d9062cc35aa9c95bd59 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 10 Dec 2019 08:40:54 -0600 Subject: [PATCH 27/31] add files --- .../Broadcasting/BroadcastManagerTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/Integration/Broadcasting/BroadcastManagerTest.php diff --git a/tests/Integration/Broadcasting/BroadcastManagerTest.php b/tests/Integration/Broadcasting/BroadcastManagerTest.php new file mode 100644 index 000000000000..51e1c2591679 --- /dev/null +++ b/tests/Integration/Broadcasting/BroadcastManagerTest.php @@ -0,0 +1,67 @@ + Date: Tue, 10 Dec 2019 08:41:32 -0600 Subject: [PATCH 28/31] Apply fixes from StyleCI (#30803) --- tests/Integration/Broadcasting/BroadcastManagerTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Integration/Broadcasting/BroadcastManagerTest.php b/tests/Integration/Broadcasting/BroadcastManagerTest.php index 51e1c2591679..af00462e6406 100644 --- a/tests/Integration/Broadcasting/BroadcastManagerTest.php +++ b/tests/Integration/Broadcasting/BroadcastManagerTest.php @@ -7,9 +7,7 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Support\Facades\Broadcast; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Queue; -use Illuminate\Support\Str; use Orchestra\Testbench\TestCase; /** From e32442bb51c73d3479fca9f7c8f9de136017726a Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 10 Dec 2019 16:48:06 +0100 Subject: [PATCH 29/31] [6.x] Implement withoutRelations method (#30802) * Implement withoutRelations method This will allow to unload all of the model's relations so it can be used, for example, to not overload queued jobs. * Rework to clone object --- .../Eloquent/Concerns/HasRelationships.php | 24 +++++++++++++++++++ .../Database/DatabaseEloquentRelationTest.php | 21 ++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php b/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php index 89a0e7272a7c..929a234cd611 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php @@ -722,6 +722,30 @@ protected function newRelatedInstance($class) }); } + /** + * Duplicate the instance and unset all the loaded relations. + * + * @return $this + */ + public function withoutRelations() + { + $model = clone $this; + + return $model->unsetRelations(); + } + + /** + * Unset all the loaded relations for the instance. + * + * @return $this + */ + public function unsetRelations() + { + $this->relations = []; + + return $this; + } + /** * Get all the loaded relations for the instance. * diff --git a/tests/Database/DatabaseEloquentRelationTest.php b/tests/Database/DatabaseEloquentRelationTest.php index f2fc3247631c..baf550256244 100755 --- a/tests/Database/DatabaseEloquentRelationTest.php +++ b/tests/Database/DatabaseEloquentRelationTest.php @@ -234,6 +234,27 @@ public function testSettingMorphMapWithNumericKeys() Relation::morphMap([], false); } + public function testWithoutRelations() + { + $original = new EloquentNoTouchingModelStub; + + $original->setRelation('foo', 'baz'); + + $this->assertEquals('baz', $original->getRelation('foo')); + + $model = $original->withoutRelations(); + + $this->assertInstanceOf(EloquentNoTouchingModelStub::class, $model); + $this->assertTrue($original->relationLoaded('foo')); + $this->assertFalse($model->relationLoaded('foo')); + + $model = $original->unsetRelations(); + + $this->assertInstanceOf(EloquentNoTouchingModelStub::class, $model); + $this->assertFalse($original->relationLoaded('foo')); + $this->assertFalse($model->relationLoaded('foo')); + } + public function testMacroable() { Relation::macro('foo', function () { From c75bc43833dc3c1e9bfd3e8ea011cd1dd2834cc9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 10 Dec 2019 09:49:16 -0600 Subject: [PATCH 30/31] reorganize --- .../Eloquent/Concerns/HasRelationships.php | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php b/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php index 929a234cd611..3c5c928293fd 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php @@ -722,30 +722,6 @@ protected function newRelatedInstance($class) }); } - /** - * Duplicate the instance and unset all the loaded relations. - * - * @return $this - */ - public function withoutRelations() - { - $model = clone $this; - - return $model->unsetRelations(); - } - - /** - * Unset all the loaded relations for the instance. - * - * @return $this - */ - public function unsetRelations() - { - $this->relations = []; - - return $this; - } - /** * Get all the loaded relations for the instance. * @@ -818,6 +794,30 @@ public function setRelations(array $relations) return $this; } + /** + * Duplicate the instance and unset all the loaded relations. + * + * @return $this + */ + public function withoutRelations() + { + $model = clone $this; + + return $model->unsetRelations(); + } + + /** + * Unset all the loaded relations for the instance. + * + * @return $this + */ + public function unsetRelations() + { + $this->relations = []; + + return $this; + } + /** * Get the relationships that are touched on save. * From ba4204f3a8b9672b6116398c165bd9c0c6eac077 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 10 Dec 2019 10:01:57 -0600 Subject: [PATCH 31/31] version --- src/Illuminate/Foundation/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 4c91947f00d9..e4fad07efbb1 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -31,7 +31,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn * * @var string */ - const VERSION = '6.6.2'; + const VERSION = '6.7.0'; /** * The base path for the Laravel installation.