Skip to content

Commit 07e56ff

Browse files
committed
Make Get Attribute repeatable and therefore allow multiple get routes to be added to a method.
1 parent 10af3aa commit 07e56ff

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Attributes/Get.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Attribute;
66

7-
#[Attribute(Attribute::TARGET_METHOD)]
7+
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
88
class Get extends Route
99
{
1010
public function __construct(

tests/AttributeTests/GetAttributeTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Spatie\RouteAttributes\Tests\TestCase;
66
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\GetTestController;
7+
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\GetMultipleTestController;
78

89
class GetAttributeTest extends TestCase
910
{
@@ -16,4 +17,15 @@ public function it_can_register_a_get_route()
1617
->assertRegisteredRoutesCount(1)
1718
->assertRouteRegistered(GetTestController::class, 'myGetMethod', 'get', 'my-get-method');
1819
}
20+
21+
/** @test */
22+
public function it_can_register_multiple_get_routes()
23+
{
24+
$this->routeRegistrar->registerClass(GetMultipleTestController::class);
25+
26+
$this
27+
->assertRegisteredRoutesCount(2)
28+
->assertRouteRegistered(GetMultipleTestController::class, 'myGetMethod', 'get', 'my-get-method')
29+
->assertRouteRegistered(GetMultipleTestController::class, 'myGetMethod', 'get', 'my-other-get-method');;
30+
}
1931
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Spatie\RouteAttributes\Tests\TestClasses\Controllers;
4+
5+
use Spatie\RouteAttributes\Attributes\Get;
6+
7+
class GetMultipleTestController
8+
{
9+
#[Get('my-get-method')]
10+
#[Get('my-other-get-method')]
11+
public function myGetMethod()
12+
{
13+
}
14+
}

0 commit comments

Comments
 (0)