【问题标题】:Rid of {one?}/{two?}/{three?}/{four?}/{five?} string in Laravel 5 routes摆脱 Laravel 5 路线中的 {one?}/{two?}/{three?}/{four?}/{five?} 字符串
【发布时间】:2016-07-29 09:13:39
【问题描述】:

我正在寻找一个选项,如何从路线中删除 {one?}/{two?}/{three?}/{four?}/{five?} this。 这会自动添加到每条路线中 喜欢

v1/webapi/login/{one?}/{two?}/{three?}/{four?}/{five?}
v1/webapi/logout/{one?}/{two?}/{three?}/{four?}/{five?}

在路由文件 m 中使用下面的路由

Route::group(['prefix' => 'v1', 'middleware' => 'webapi'], function(){
    Route::controller('webapi', 'WebApiController');
});

谁能有同样的问题?

【问题讨论】:

  • 你能显示webapi的代码吗?
  • webapi 是控制器文件,我在其中编写了所有功能

标签: php laravel laravel-5 controller routes


【解决方案1】:

简短的回答是 - 您无法删除它。这个方法https://github.com/laravel/framework/blob/5.2/src/Illuminate/Routing/ControllerInspector.php#L132添加了那些通配符参数。

摆脱它的唯一方法是重写Router并使用你自己的ControllerInspector,但这毫无意义而且很难实现。


更新

但如果你真的想这样做,有一个 hacky 解决方案:

    foreach (\Route::getRoutes() as $route) {
        $route->setUri(preg_replace('%\{one\?\}/\{two\?\}/\{three\?\}/\{four\?\}/\{five\?\}$%', '',
            $route->getUri()));
    }

将此代码放入RouteServiceProvider.php boot 方法中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 2020-04-02
    • 2014-03-24
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多