diff --git a/src/Illuminate/Database/Eloquent/Relations/Relation.php b/src/Illuminate/Database/Eloquent/Relations/Relation.php index cba4ca2afed0..ca5dc6516d03 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Relation.php +++ b/src/Illuminate/Database/Eloquent/Relations/Relation.php @@ -509,7 +509,7 @@ public static function getMorphedModel($alias) */ public static function getMorphAlias(string $className) { - return array_flip(static::$morphMap)[$className] ?? null; + return array_search($className, static::$morphMap, strict: true) ?: $className; } /** diff --git a/tests/Database/DatabaseEloquentRelationTest.php b/tests/Database/DatabaseEloquentRelationTest.php index 47bd92710bcf..0fac8f8d3b7f 100755 --- a/tests/Database/DatabaseEloquentRelationTest.php +++ b/tests/Database/DatabaseEloquentRelationTest.php @@ -239,8 +239,8 @@ public function testGetMorphAlias() { Relation::morphMap(['user' => 'App\User']); - $this->assertEquals('user', Relation::getMorphAlias('App\User')); - $this->assertNull(Relation::getMorphAlias('Does\Not\Exist')); + $this->assertSame('user', Relation::getMorphAlias('App\User')); + $this->assertSame('Does\Not\Exist', Relation::getMorphAlias('Does\Not\Exist')); } public function testWithoutRelations()