From 10a6df9260c4721c7d49438b8fc155fcb975c458 Mon Sep 17 00:00:00 2001 From: Eduard Date: Wed, 25 Jul 2018 01:15:01 +0300 Subject: [PATCH] Cast to int when fetching BelongsToMany values --- src/Traits/LoopsOverRelations.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Traits/LoopsOverRelations.php b/src/Traits/LoopsOverRelations.php index c32a96c..9ede5ea 100755 --- a/src/Traits/LoopsOverRelations.php +++ b/src/Traits/LoopsOverRelations.php @@ -35,10 +35,13 @@ protected function fetchRelationValue($eloquent, $name, array $relations = [], $ // Treat BelongsToMany form relation as array of values. if ($object instanceof BelongsToMany) { - return \DB::table($object->getTable()) - ->where($this->getQualifiedForeignKeyName($object), $orig->getKey()) - ->pluck($this->getQualifiedRelatedKeyName($object)) - ->toArray(); + return array_map( + 'intval', + \DB::table($object->getTable()) + ->where($this->getQualifiedForeignKeyName($object), $orig->getKey()) + ->pluck($this->getQualifiedRelatedKeyName($object)) + ->toArray() + ); } $object = $object->getResults();