我遇到[Route::group(['middleware' => ['web']], function () {}); ]
的问题
当我在路线文件中使用它时,它会显示以下错误:
FatalErrorException in Container.php line 702:
Maximum function nesting level of '100' reached, aborting!
我的routes.php是:
use App\Discussion;
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
});
Route::auth();
});
Route::get('home', function () {
$discussion = Discussion::orderBy('created_at', 'asc')->get();
return view('home', [
'discussions' => $discussion,
]);
});
这是homeController:
<?php
namespace App\Http\Controllers;
use App\Discussion;
use App\Http\Requests;
use App\User;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
}
}
这是错误:
FatalErrorException in Container.php line 702:
Maximum function nesting level of '100' reached, aborting!
in Container.php line 702
at FatalErrorException->__construct() in HandleExceptions.php line 133
at HandleExceptions->fatalExceptionFromError() in HandleExceptions.php line 118
at HandleExceptions->handleShutdown() in HandleExceptions.php line 0
at Container->normalize() in Container.php line 179
at Container->bind() in Container.php line 1199
at Container->offsetSet() in Container.php line 39
at AuthServiceProvider->Illuminate\Auth\{closure}() in Container.php line 735
at Container->build() in Container.php line 633
at Container->make() in Application.php line 697
at Application->make() in Container.php line 1178
at Container->offsetGet() in Facade.php line 151
at Facade::resolveFacadeInstance() in Facade.php line 120
at Facade::getFacadeRoot() in Facade.php line 207
at Facade::__callStatic() in f6edb10b0490bd0fe5a2fb364a623ddb1e0231d4.php line 56
at Auth::guest() in f6edb10b0490bd0fe5a2fb364a623ddb1e0231d4.php line 56
in PhpEngine.php line 42
at PhpEngine->evaluatePath() in CompilerEngine.php line 59
at CompilerEngine->get() in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in aa3aed20f72e2364ebd8d243052a41cdb52d5295.php line 17
in PhpEngine.php line 42
at PhpEngine->evaluatePath() in CompilerEngine.php line 59
at CompilerEngine->get() in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 53
at Response->setContent() in Response.php line 199
at Response->__construct() in Router.php line 1087
at Router->prepareResponse() in Router.php line 725
at Router->Illuminate\Routing\{closure}() in Pipeline.php line 52
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:52}() in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}() in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in StartSession.php line 62
at StartSession->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in EncryptCookies.php line 59
at EncryptCookies->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in StartSession.php line 62
at StartSession->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in EncryptCookies.php line 59
at EncryptCookies->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in Pipeline.php line 103
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:103}() in Pipeline.php line 103
at Pipeline->then() in Router.php line 726
at Router->runRouteWithinStack() in Router.php line 699
at Router->dispatchToRoute() in Router.php line 675
at Router->dispatch() in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}() in Pipeline.php line 52
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:52}() in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}() in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle() in Pipeline.php line 136
at call_user_func_array:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:136}() in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}() in Pipeline.php line 32
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:32}() in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}() in Pipeline.php line 103
at call_user_func:{C:\wamp\www\social\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:103}() in Pipeline.php line 103
at Pipeline->then() in Kernel.php line 132
at Kernel->sendRequestThroughRouter() in Kernel.php line 99
at Kernel->handle() in index.php line 54
in server.php line 21
at {main}() in server.php line 0
答案 0 :(得分:2)
从Laravel 5.2开始,所有路由都包含Web Middleware
,因此没有理由再定义Route::group(['middleware' => ['web']);
。
在RouteServiceProvider中:
protected function mapWebRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace, 'middleware' => 'web',
], function ($router) {
require app_path('Http/routes.php');
});
}
由同一文件中的上一个函数实例化:
public function map(Router $router)
{
$this->mapWebRoutes($router);
//
}
由Kernel
堆栈调用。
这应解决嵌套问题。