Routes 如何使用root配置路由资源

Routes 如何使用root配置路由资源,routes,laravel-5,Routes,Laravel 5,我正在使用Laravel5.1,并创建一个路由资源,如:route::resource(“/page”,“PagesController”)。但是我不希望/page成为我的资源,或者/page/about。我宁愿要/about等等 当我使用Route::resource('/','PagesController')get('/'),'PagesController@index”;等等,但每件事都有一个这样做似乎是错误的 我如何设置路由资源,以便在根目录下使用参数?我遇到了与您相同的问题,但我找不

我正在使用Laravel5.1,并创建一个路由资源,如:
route::resource(“/page”,“PagesController”)。但是我不希望
/page
成为我的资源,或者
/page/about
。我宁愿要
/about
等等

当我使用
Route::resource('/','PagesController')
Route::resource('/page', 'PagesController', [
    'names' => [
        'index' => 'pages.index',
        'show' => 'pages.show',
        'create' => 'pages.create',
        'store' => 'pages.store',
        'edit' => 'pages.edit',
        'update' => 'pages.update',
        'destroy' => 'pages.destroy'
    ]
]);
这使得
/
将我带到索引文件,但是
/about
等都不起作用,因为URI(显示为
{}
)没有任何参数

我可以使用
$router->get('/'),'PagesController@index”;
等等,但每件事都有一个这样做似乎是错误的


我如何设置路由资源,以便在根目录下使用参数?

我遇到了与您相同的问题,但我找不到任何解决方案

查看laravel/framework/src/illighte/Routing/resourceRegister.php中的register函数,我们可以看到在这种情况下$base为null:

// We need to extract the base resource from the resource name. Nested resources
// are supported in the framework, but we need to know what name to use for a
// place-holder on the route wildcards, which should be the base resources.
$base = $this->getResourceWildcard(last(explode('.', $name)));

$defaults = $this->resourceDefaults;

foreach ($this->getResourceMethods($defaults, $options) as $m) {
    $this->{'addResource'.ucfirst($m)}($name, $base, $controller, $options);
}
这会导致添加方法出错:

 * Add the show method for a resourceful route.
 *
 * @param  string  $name
 * @param  string  $base
 * @param  string  $controller
 * @param  array   $options
 * @return \Illuminate\Routing\Route
 */
protected function addResourceShow($name, $base, $controller, $options)
{
    $uri = $this->getResourceUri($name).'/{'.$base.'}';

    $action = $this->getResourceAction($name, $controller, 'show', $options);

    return $this->router->get($uri, $action);
}
我不确定除了手动添加每个方法之外我们是否还能做些什么,但这就是我在本例中所做的