Maximum function nesting level of ‘100’ reached, aborting Laravel 5.1

I am making an ecommerce web application in Laravel 5.1. While examining the application’s admin panel for editing a particular product, I got an exception:

FatalErrorException in Container.php line 1057:
Maximum function nesting level of '100' reached, aborting!

I have implemented Repository Pattern in my application and it is still in development stage.

Here’s the stack trace:

in Container.php line 1057
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->make() in Application.php line 674
at Application->make() in Container.php line 1157
at Container->offsetGet() in DatabaseManager.php line 251
at DatabaseManager->getDefaultConnection() in DatabaseManager.php line 85
at DatabaseManager->parseConnectionName() in DatabaseManager.php line 61
at DatabaseManager->connection() in Model.php line 3209
at Model::resolveConnection() in Model.php line 3175
at Model->getConnection() in Model.php line 2946
at Model->getDateFormat() in Model.php line 2879
at Model->fromDateTime() in Model.php line 2838
at Model->setAttribute() in Model.php line 422
at Model->fill() in Model.php line 445
at Model->IlluminateDatabaseEloquent{closure}() in Model.php line 2295
at Model::unguarded() in Model.php line 446
at Model->forceFill() in Pivot.php line 54
at Pivot->__construct() in Model.php line 1937
at Model->newPivot() in BelongsToMany.php line 1124
at BelongsToMany->newPivot() in BelongsToMany.php line 1137
at BelongsToMany->newExistingPivot() in BelongsToMany.php line 257
at BelongsToMany->hydratePivotRelation() in BelongsToMany.php line 178
at BelongsToMany->get() in BelongsToMany.php line 99
at BelongsToMany->getResults() in Model.php line 2699
at Model->getRelationshipFromMethod() in Model.php line 2665
at Model->getRelationValue() in Model.php line 2607
at Model->getAttribute() in Model.php line 3325
at Model->__get() in Model.php line 46
at Product->getCategoryIdAttribute() in Model.php line 2722
at Model->mutateAttribute() in Model.php line 2624
at Model->getAttributeValue() in Model.php line 3394
at Model->__isset() in FormBuilder.php line 3348
at Model->offsetExists() in FormBuilder.php line 404
at data_get() in FormBuilder.php line 1048
at FormBuilder->getModelValueAttribute() in FormBuilder.php line 1035
at FormBuilder->getValueAttribute() in FormBuilder.php line 487
at FormBuilder->select() in Facade.php line 219
at Facade::__callStatic() in 400c2ba760310cd2966e41d1b593cf85 line 24
at FormFacade::select() in 400c2ba760310cd2966e41d1b593cf85 line 24
in PhpEngine.php line 42
at PhpEngine->evaluatePath() in CompilerEngine.php line 58
at CompilerEngine->get() in View.php line 138
at View->getContents() in View.php line 107
at View->renderContents() in View.php line 81
at View->render() in e6c9a42799c231accc0d1cb4aa2d16d0 line 47
in PhpEngine.php line 42
at PhpEngine->evaluatePath() in CompilerEngine.php line 58
at CompilerEngine->get() in View.php line 138
at View->getContents() in View.php line 107
at View->renderContents() in View.php line 81
at View->render() in Response.php line 51
at Response->setContent() in Response.php line 202
at Response->__construct() in Router.php line 1225
at Router->prepareResponse() in ControllerDispatcher.php line 113
at ControllerDispatcher->IlluminateRouting{closure}() in Pipeline.php line 139
at call_user_func() in Pipeline.php line 139
at Pipeline->IlluminatePipeline{closure}() in AdminLoggedIn.php line 20
at AdminLoggedIn->handle() in Pipeline.php line 124
at call_user_func_array() in Pipeline.php line 124
at Pipeline->IlluminatePipeline{closure}() in Pipeline.php line 103
at call_user_func() in Pipeline.php line 103
at Pipeline->then() in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack() in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch() in Route.php line 201
at Route->runWithCustomDispatcher() in Route.php line 134
at Route->run() in Router.php line 704
at Router->IlluminateRouting{closure}() in Pipeline.php line 139
at call_user_func() in Pipeline.php line 139
at Pipeline->IlluminatePipeline{closure}() in Pipeline.php line 103
at call_user_func() in Pipeline.php line 103
at Pipeline->then() in Router.php line 706
at Router->runRouteWithinStack() in Router.php line 671
at Router->dispatchToRoute() in Router.php line 631
at Router->dispatch() in Kernel.php line 236
at Kernel->IlluminateFoundationHttp{closure}() in Pipeline.php line 139
at call_user_func() in Pipeline.php line 139
at Pipeline->IlluminatePipeline{closure}() in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle() in Pipeline.php line 124
at call_user_func_array() in Pipeline.php line 124
at Pipeline->IlluminatePipeline{closure}() in ShareErrorsFromSession.php line 54
at ShareErrorsFromSession->handle() in Pipeline.php line 124
at call_user_func_array() in Pipeline.php line 124
at Pipeline->IlluminatePipeline{closure}() in StartSession.php line 62
at StartSession->handle() in Pipeline.php line 124
at call_user_func_array() in Pipeline.php line 124
at Pipeline->IlluminatePipeline{closure}() in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle() in Pipeline.php line 124
at call_user_func_array() in Pipeline.php line 124
at Pipeline->IlluminatePipeline{closure}() in EncryptCookies.php line 59
at EncryptCookies->handle() in Pipeline.php line 124
at call_user_func_array() in Pipeline.php line 124
at Pipeline->IlluminatePipeline{closure}() in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle() in Pipeline.php line 124
at call_user_func_array() in Pipeline.php line 124
at Pipeline->IlluminatePipeline{closure}() in Pipeline.php line 103
at call_user_func() in Pipeline.php line 103
at Pipeline->then() in Kernel.php line 122
at Kernel->sendRequestThroughRouter() in Kernel.php line 87
at Kernel->handle() in index.php line 54
in server.php line 21
at {main}() in server.php line 0

The problem is when I try to edit the product from the admin panel, I get the above exception, though I can insert a new product from the admin panel.

I know that I can increase the xdebug.max_nesting_level = 100 to xdebug.max_nesting_level = 500, but this is not what I am looking for. I am developing the application for a client and they, probably, are having their own server. Thus, I cannot use this as my solution.

By doing some research, I was brought to this question, but the accepted answer is using wamp as his server and I am using LAMP.

What / where is the mistake that I have made ?

Any help is highly appreciated. Thanks.

UPDATE 1:

After bit of study of the stack trace, I found that, it is with the form that I am using:

form.blade.php

<div class="row">
    <div class="col-md-4 col-sm-6">
        <div class="form-group">
            {!! Form::label('code', 'Code:') !!}
            {!! Form::text('code', null, ['class' => 'form-control input-sm']) !!}
        </div>
    </div>

    <div class="col-md-4 col-sm-6">
        <div class="form-group">
            {!! Form::label('name', 'Name:') !!}
            {!! Form::text('name', null, ['class' => 'form-control input-sm']) !!}
        </div>
    </div>

    <div class="col-md-4 col-sm-6">
        <div class="form-group">
            {!! Form::label('category_id', 'Category:') !!}
            <!-- Here's the error: $categoryList -->
            {!! Form::select('category_id[]', $categoryList, null, ['class' => 'form-control input-sm categoryList', 'multiple']) !!}
        </div>
    </div>
</div>


<div class="row">
    <div class="col-md-4 col-sm-6">
        <div class="form-group">
            {!! Form::label('sort', 'Sort:') !!}
            {!! Form::text('sort', null, ['class' => 'form-control input-sm']) !!}
        </div>
    </div>

    <div class="col-md-12 col-sm-12">
        <div class="form-group">
            {!! Form::label('special_note', 'Special Note:') !!}
            {!! Form::textarea('special_note', null, ['class' => 'form-control input-sm ckeditor', 'id' => 'prdSpecialNote'] ) !!}
        </div>
    </div>
</div>

<div class="form-group">
    {!! Form::submit($submitButtonText, ['class' => 'btn btn-primary btn-block', 'id' => $submitButtonId]) !!}
</div>

Product.php

<?php

namespace App;

use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;

class Product extends Model
{
    use SoftDeletes;

    /**
     * The dates that will be used as Carbon instance
     * 
     * @var array
     */
    protected $dates = ['deleted_at'];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'code', 'name', 'description', 'special_note', 'sort', 'display'
    ];

    /**
     * The Many-To-Many relationship between the category and
     * the product.
     * 
     * @return IlluminateDatabaseEloquentRelationsBelongsToMany
     */
    public function categories()
    {
        return $this->belongsToMany('AppCategory')->withTimestamps();
    }

    /**
     * Get the array of AppCategory.
     * 
     * @return array
     */
    public function getCategoryIdAttribute()
    {
        // If I comment this line, the error disappears
        // but the category_id field becomes blank
        // And if I leave it as it is
        // It throws the error exception

        return $this->categories->lists('id');
    }
}

P.S. I am using Ubuntu 14.04 LTS x64bit Architecture with LAMP installed. Also I am using Form Model Binding.


Source: laravel

Leave a Reply