Skip to content

Commit

Permalink
Fix route name duplicating prefix and module
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro authored and ifox committed May 10, 2021
1 parent ce75aff commit f446363
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Helpers/routes_helpers.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Illuminate\Support\Str;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Str;

if (!function_exists('moduleRoute')) {
/**
Expand Down
39 changes: 20 additions & 19 deletions src/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ private function mapInternalRoutes(
$router->group(
[
'middleware' => $supportSubdomainRouting
? ['supportSubdomainRouting']
: [],
? ['supportSubdomainRouting']
: [],
],
function ($router) {
require __DIR__ . '/../routes/auth.php';
Expand All @@ -101,8 +101,8 @@ function ($router) {
$router->group(
[
'middleware' => $this->app->environment('production')
? ['twill_auth:twill_users']
: [],
? ['twill_auth:twill_users']
: [],
],
function ($router) {
require __DIR__ . '/../routes/templates.php';
Expand All @@ -126,9 +126,9 @@ function ($router) use ($internalRoutes, $supportSubdomainRouting) {
$router->group(
[
'domain' =>
config('twill.admin_app_subdomain', 'admin') .
'.{subdomain}.' .
config('app.url'),
config('twill.admin_app_subdomain', 'admin') .
'.{subdomain}.' .
config('app.url'),
],
$internalRoutes
);
Expand All @@ -151,8 +151,8 @@ function ($router) {
'middleware' => $this->app->environment(
'production'
)
? ['twill_auth:twill_users']
: [],
? ['twill_auth:twill_users']
: [],
],
function ($router) {
require __DIR__ . '/../routes/templates.php';
Expand Down Expand Up @@ -221,13 +221,13 @@ protected function registerMacros()
}

$routePrefix = empty($routePrefix)
? '/'
: (Str::startsWith($routePrefix, '/')
? $routePrefix
: '/' . $routePrefix);
$routePrefix = Str::endsWith($routePrefix, '/')
? '/'
: (Str::startsWith($routePrefix, '/')
? $routePrefix
: $routePrefix . '/';
: '/' . $routePrefix);
$routePrefix = Str::endsWith($routePrefix, '/')
? $routePrefix
: $routePrefix . '/';

Route::name($moduleName . '.show')->get(
$routePrefix . '{slug}',
Expand Down Expand Up @@ -310,11 +310,12 @@ protected function registerMacros()
}

// Check if name will be a duplicate, and prevent if needed/allowed
if (
!empty($groupPrefix) &&
(blank($lastRouteGroupName) ||
if (!empty($groupPrefix) &&
(
blank($lastRouteGroupName) ||
config('twill.allow_duplicates_on_route_names', true) ||
!Str::endsWith($lastRouteGroupName, ".{$groupPrefix}."))
(!Str::endsWith($lastRouteGroupName, ".{$groupPrefix}."))
)
) {
$customRoutePrefix = "{$groupPrefix}.{$slug}";
$resourceCustomGroupPrefix = "{$groupPrefix}.";
Expand Down

0 comments on commit f446363

Please sign in to comment.