12

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!

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.

Community
  • 1
  • 1
Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68
  • 1
    You must have initialised a class A in the constructor of class B, and class A must be initialising class B, and so it stucks in forever loop Can you share your code so that i can exactly see whats going on. – Ammar Ajmal Feb 07 '16 at 13:23
  • @AmmarAjmal I just install laravel 5.2 authentication module, there is not additional code. – Ayaz Ali Shah Feb 07 '16 at 13:25
  • I got this error right now. any solutions yet? – Rabb-bit Feb 11 '16 at 16:45
  • Possible duplicate of [Maximum function nesting level of '100' reached, aborting after upgrading to Laravel 5.1](http://stackoverflow.com/questions/30803342/maximum-function-nesting-level-of-100-reached-aborting-after-upgrading-to-lar) – Abrar Jahin Oct 19 '16 at 18:58
  • In my case, it is caused right where I declare, in my Model class, the `protected $with = ['relationship1', 'relationship2'];` in Laravel 5.6 – Pathros Sep 26 '18 at 14:30
  • 1
    @Pathros are you facing same problem in 5.6? – Ayaz Ali Shah Sep 26 '18 at 14:32
  • @AyazShah. Yes. I have just discovered why this is happening: I got this one-to-many relationship. That is to say, in model `Research` I have a list. And in `Subject` model, I have another list of subjects that belong to a specific register of Research. Well, declaring `protected $with = ['relationships'];` on both sides are causing this `Maximum function nesting level` error. So i have to leave just one `$with`, in one of these two models, and the error goes away. – Pathros Sep 26 '18 at 21:19

7 Answers7

23

This usually happens because you are loading the relations from the two models at once by something like $with property.

Let's say a Category hasMany Product and a Product belongsTo a Category.

If in both models you load the relations by default like this: 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.

Also this could happen with GlobalScopes and the idea is similar to $with property.

Yamen Ashraf
  • 2,637
  • 2
  • 20
  • 26
21

Issue is caused by default xdebug.max_nesting_level which is 100.

The workaround for now is to increase xdebug.max_nesting_level to a certain level say 200 or 300 or 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

ini_set('xdebug.max_nesting_level', 120);

............

define('LARAVEL_START', microtime(true));
Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68
DucaBgd
  • 276
  • 3
  • 4
3

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()...

supernifty
  • 4,171
  • 2
  • 32
  • 24
2

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.

It was a loop that has broken - toArray()

The error I got on my Laravel 5.7 was:

Maximum function nesting level of '512' reached, aborting!

Solution

go to Address model and add the protected attribute

protected $hidden = ['user']; // for toArray
Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191
  • Well the error came up when I was using `laravel-5.2` but thank you so much I will keep in mind the solution in my future projects. I appreciate – Ayaz Ali Shah Nov 07 '18 at 05:18
  • This problem ans solution would be the same for Laravel 5.2, even though I did not test it on all the versions of Laravel. – Yevgeniy Afanasyev Nov 07 '18 at 05:50
1

I had a Global Scope on my User Model that used Auth::check(), causing a loop.

Shawn Pivonka
  • 335
  • 3
  • 14
0

Just put the line

ini_set('xdebug.max_nesting_level', 120);

in the file bootstrap/autoload.php in the Laravel 5.2

Works fine for me.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
Reta110
  • 19
  • 2
0

I got this error here:
xdebug.max_nesting_level is set to 500

$guards = array_keys(config('auth.guards'));
$this->authenticate($request, $guards);
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Mike
  • 67
  • 11