From 1fb3df211384a72250cad02a3b77de7a89656761 Mon Sep 17 00:00:00 2001 From: RytisT Date: Thu, 2 Feb 2017 15:37:22 +0200 Subject: [PATCH] Sort foreign keys in with() method --- src/Illuminate/Database/Eloquent/Relations/BelongsTo.php | 2 ++ src/Illuminate/Database/Eloquent/Relations/Relation.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php b/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php index 94c42b4160c1..a0b9011e7d35 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php @@ -134,6 +134,8 @@ protected function getEagerModelKeys(array $models) return [$this->relationHasIncrementingId() ? 0 : null]; } + sort($keys); + return array_values(array_unique($keys)); } diff --git a/src/Illuminate/Database/Eloquent/Relations/Relation.php b/src/Illuminate/Database/Eloquent/Relations/Relation.php index de4cf639b764..acbfbede1aa1 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Relation.php +++ b/src/Illuminate/Database/Eloquent/Relations/Relation.php @@ -205,7 +205,7 @@ protected function getKeys(array $models, $key = null) { return collect($models)->map(function ($value) use ($key) { return $key ? $value->getAttribute($key) : $value->getKey(); - })->values()->unique()->all(); + })->values()->unique()->sort()->all(); } /**