How to fix laravel 5.2 this error "Maximum function nesting level of '100' reached, aborting!"?
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.
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));