RouteCompiler中的Laravel DomainException变量名称在路由模式中不能超过32个字符

Jos*_*itt 5 php laravel laravel-5

由于变量名太长,导致出现此错误。如何覆盖变量名?

我非常想保留资源名称。

我的路线是:

Route::resource(
    'computer-software-version-installation',
    'Web\Model\ComputerSoftwareVersionInstallationController'
);
Run Code Online (Sandbox Code Playgroud)

Jos*_*itt 7

这是我要解决的问题:

    Route::resource(
        'computer-software-version-installation',
        'Web\Model\ComputerSoftwareVersionInstallationController',
        ['parameters' => [
            'computer-software-version-installation' => 'installation'
        ]]
    );
Run Code Online (Sandbox Code Playgroud)

为什么这是必要的?

对于Laravel 5.3,这是扩展的答案:

照亮\路由\路由器resource的方法创建一个新的ResourceRegistrar注册路线。此方法作为$options参数。

照亮\路由\ ResourceRegistrar register方法将设置参数属性的$options['parameters']值,然后调用getResourceWildcard以设置$base使用的最后一部分变量值$name作为输入参数。

照亮\路由\ ResourceRegistrar getResourceWildcard方法会去翻参数,看看是否有一个值,并使用它,如果有。否则,它会经过一些旋转来制成琴弦。

因此,如果我们传入'parameters'一个键,该键与路由名称匹配,并且该值等于占位符名称,则可以避免该错误。

getResourceWildcard这里提到的问题:

https://github.com/laravel/framework/issues/1001#issuecomment-134887584

但似乎在这里被认为是交响乐问题?

https://github.com/laravel/framework/issues/1001#issuecomment-212518768

希望这个答案可以帮助其他人解决。但是它尚未经过广泛测试,因此可能仍然存在问题。