laravel-nestedset icon indicating copy to clipboard operation
laravel-nestedset copied to clipboard

children relationship is not loaded from model to array

Open schel4ok opened this issue 3 years ago • 0 comments

I have database request with data serialized to array

		$columns = ['id', '_lft', '_rgt', 'parent_id', 'title', 'slug', 'icon', 'description', 'image', 'metatitle', 'metakey', 'metadesc'];

		$result = $this
			->startConditions()
			->whereSlug($slug)
			->select($columns)	
			->first()
			->toArray();

And in output array I see only ancestors relationship. I don't see children. If I debug like that I see only ancestors in array.

		$result = $this
			->startConditions()
			->whereSlug($slug)
			->select($columns)	
			->first();

		dd($result, $result->toArray());

but if I try to debug like that then I see children

		dd($result, $result->children, $result->toArray());

What is the problem and how I can get children in my array?

At the moment I solved like that, but it seems like a croocked path.

		$result = $this
			->startConditions()
			->whereSlug($slug)
			->select($columns)	
			->first();

		$result->children = $result->children->toArray();
		$result = $result->toArray();

schel4ok avatar Mar 09 '22 14:03 schel4ok