diff --git a/src/Laravel/Middleware/SubstituteEnums.php b/src/Laravel/Middleware/SubstituteEnums.php index e608af8..fd75f3d 100644 --- a/src/Laravel/Middleware/SubstituteEnums.php +++ b/src/Laravel/Middleware/SubstituteEnums.php @@ -66,7 +66,7 @@ private function getParameters(Route|null $route): array $route?->signatureParameters(['subClass' => UnitEnum::class]) )->mapWithKeys( function (ReflectionParameter $parameter) { - $backedEnumClass = rtrim((string)$parameter->getType(), '?'); + $backedEnumClass = ltrim((string)$parameter->getType(), '?'); if (enum_exists($backedEnumClass)) { return [$parameter->getName() => new ReflectionEnum($backedEnumClass)]; diff --git a/tests/Unit/Laravel/Middleware/SubstituteEnumsTest.php b/tests/Unit/Laravel/Middleware/SubstituteEnumsTest.php index 3730c33..391cfcf 100644 --- a/tests/Unit/Laravel/Middleware/SubstituteEnumsTest.php +++ b/tests/Unit/Laravel/Middleware/SubstituteEnumsTest.php @@ -59,6 +59,7 @@ function (SimpleEnum $status) { $router->get('/optional/{status?}', function (SimpleEnum $status = null) { + return $status?->name; } ); @@ -83,7 +84,8 @@ public function testShouldBindBasicEnum() public function testShouldBindBasicEnumOptionally() { - $this->get('/optional/')->assertOk(); + // $this->get('/optional/')->assertOk()->assertSee(''); + $this->get('/optional/open')->assertOk()->assertSee('Open'); } public function testShouldBindBasicEnumWithDefault()