belongsToMany(Folder::class, 'folder_closure', 'ancestor_id', 'descendant_id') ->withPivot('depth'); } public function documents() { return $this->hasMany(Document::class); } public function parent() { return $this->belongsTo(Folder::class, 'parent_id'); } public function children() { return $this->hasMany(Folder::class, 'parent_id')->with('children'); } public function project() { return $this->belongsTo(Project::class); } }