如何修复 Laravel 5.2 这个错误“达到了'100'的最大函数嵌套级别,正在中止!”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35253984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix laravel 5.2 this error "Maximum function nesting level of '100' reached, aborting!"?
提问by Ayaz Shah
I'm trying to reset password from laravel auto generated login/register authentication module. When i click on reset button it give me this error
FatalErrorException in ClassLoader.php line 344:
Maximum function nesting level of '100' reached, aborting!
我正在尝试从 Laravel 自动生成的登录/注册身份验证模块重置密码。当我点击重置按钮时,它给了我这个错误
FatalErrorException in ClassLoader.php line 344:
Maximum function nesting level of '100' reached, aborting!
I searched about it and find an accepted answer, but this answer does not work on my side i have followed the instruction. Can any one guide me it is laravel error or wamp ? and how can fix it. I would like to appreciate.
我搜索了它并找到了一个可接受的答案,但这个答案对我来说不起作用,我已经按照说明进行操作。任何人都可以指导我这是laravel错误还是wamp?以及如何修复它。我想欣赏。
回答by DucaBgd
Issue is caused by default xdebug.max_nesting_level which is 100.
问题是由默认的 xdebug.max_nesting_level 引起的,它是 100。
The workaround for now is to increase xdebug.max_nesting_level to a certain level say 200 or 300 or 400.
现在的解决方法是将 xdebug.max_nesting_level 增加到某个级别,比如 200 或 300 或 400。
I fixed mine by increasing xdebug.max_nesting_level to 120, by adding the line below to bootstrap/autoload.php
in the Laravel 5.1
我通过将 xdebug.max_nesting_level 增加到 120 来修复我的问题,方法是bootstrap/autoload.php
在 Laravel 5.1 中添加以下行
ini_set('xdebug.max_nesting_level', 120);
............
………………
define('LARAVEL_START', microtime(true));
回答by Yamen Ashraf
This usually happens because you are loading the relations from the two models at once by something like $with
property.
这通常是因为您通过$with
属性之类的东西一次从两个模型加载关系。
Let's say the a Category
hasMany Product
and a Product
belongsTo a Category
.
假设 a Category
hasManyProduct
和 a Product
ownsTo a Category
。
If in both models you load the relations by default like this:
in Product
model $with=['category']
, in Category
model $with=['products']
如果在两个模型中默认加载关系,如下所示: in Product
model $with=['category']
, in Category
model$with=['products']
this would result this infinite nesting. So, to solve this load the relations whenever wanted only.
这将导致这种无限嵌套。所以,为了解决这个负载关系,只要需要。
回答by spedley
In my case, I accidentally assigned the same name to both a class method and an imported trait resulting in a loop of $this->doThis() --> $this->doThis() --> $this->doThis() --> $this->doThis()...
就我而言,我不小心将相同的名称分配给了一个类方法和一个导入的 trait,导致 $this->doThis() --> $this->doThis() --> $this->doThis() 的循环) --> $this->doThis()...
回答by Yevgeniy Afanasyev
I had this when calling
我打电话时有这个
Illuminate\Database\Eloquent\Model->toArray()
on an User
model that has a relation to Address
model, when the Address
model has a relation to the same User
model... it was a loop.
在与User
模型有关系的Address
模型上,当Address
模型与同一User
模型有关系时……这是一个循环。
It was a loop that has broken - toArray()
这是一个已经打破的循环—— toArray()
The error I got on my Laravel 5.7 was:
我在 Laravel 5.7 上遇到的错误是:
Maximum function nesting level of '512' reached, aborting!
达到“512”的最大函数嵌套级别,中止!
Solution
解决方案
go to Address model and add the protected attribute
转到地址模型并添加受保护的属性
protected $hidden = ['user']; // for toArray
回答by Shawn Pivonka
I had a Global Scope on my User Model that used Auth::check(), causing a loop.
我的用户模型上有一个全局作用域,它使用了 Auth::check(),导致循环。
回答by Reta110
Just put the line
只需放行
ini_set('xdebug.max_nesting_level', 120);
in the file bootstrap/autoload.php in the Laravel 5.2
在 Laravel 5.2 的 bootstrap/autoload.php 文件中
Works fine for me.
对我来说很好用。