Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@
*/
'use_guarded' => false,

/*
|--------------------------------------------------------------------------
| Pluralize route names
|--------------------------------------------------------------------------
|
| By default, Blueprint will use the `kebab-case` of the controller name for
| for the route name. If you would like to ensure a plural route name is
| used, you may set this to `true`.
|
*/
'plural_routes' => null,

/*
|--------------------------------------------------------------------------
| Generators
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/RouteGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function buildRoutes(Controller $controller)
$routes = '';
$methods = array_keys($controller->methods());
$className = $this->getClassName($controller);
$slug = Str::kebab($controller->prefix());
$slug = config('blueprint.plural_routes') ? Str::plural(Str::kebab($controller->prefix())) : Str::kebab($controller->prefix());

foreach (array_diff($methods, Controller::$resourceMethods) as $method) {
$routes .= $this->buildRouteLine($className, $slug, $method);
Expand Down
35 changes: 33 additions & 2 deletions tests/Feature/Generators/RouteGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
*/
class RouteGeneratorTest extends TestCase
{
private $blueprint;

protected $files;
private $blueprint;

/** @var RouteGenerator */
private $subject;
Expand Down Expand Up @@ -71,6 +70,38 @@ public function output_generates_api_routes()
$this->assertEquals(['updated' => ['routes/api.php']], $this->subject->output($tree));
}

/**
* @test
*/
public function output_generates_routes_with_plural_slug()
{
$this->app['config']->set('blueprint.plural_routes', true);

$this->filesystem->expects('append')
->with('routes/web.php', $this->fixture('routes/readme-example-plural.php'));

$tokens = $this->blueprint->parse($this->fixture('drafts/readme-example.yaml'));
$tree = $this->blueprint->analyze($tokens);

$this->assertEquals(['updated' => ['routes/web.php']], $this->subject->output($tree));
}

/**
* @test
*/
public function output_generates_api_routes_with_plural_slug()
{
$this->app['config']->set('blueprint.plural_routes', true);

$this->filesystem->expects('append')
->with('routes/api.php', $this->fixture('routes/api-routes-plural.php'));

$tokens = $this->blueprint->parse($this->fixture('drafts/api-routes-example.yaml'));
$tree = $this->blueprint->analyze($tokens);

$this->assertEquals(['updated' => ['routes/api.php']], $this->subject->output($tree));
}

/**
* @test
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/routes/api-routes-plural.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


Route::apiResource('certificates', App\Http\Controllers\Api\CertificateController::class);
3 changes: 3 additions & 0 deletions tests/fixtures/routes/readme-example-plural.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


Route::resource('posts', App\Http\Controllers\PostController::class)->only('index', 'store');