Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ozgurzurnaci's avatar

Infinite loop problem on laravel livewire

I'm trying to create a nested tree category system in laravel livewire. Im using kalnoy/laravel-nestedset library. My livewire component codes:

app/Livewire/CategoryTree.php:

app/Model/Category.php:


namespace App\Models;
use Kalnoy\Nestedset\NodeTrait;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    use NodeTrait;

    protected $fillable = ['name', 'parent_id'];
}

this line cause the problem: $this->categories = Category::get()->toTree(); when i use the toTree() function, laravel gives this error: the error is Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '512' frames

if i use toFlatTree() function, script runs without error and i can see Categories.

i have to list categories in tree format. how can i fix this problem?

0 likes
0 replies

Please or to participate in this conversation.