Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you show how to implement? #1

Open
faiq-naseem opened this issue Aug 26, 2019 · 1 comment
Open

Can you show how to implement? #1

faiq-naseem opened this issue Aug 26, 2019 · 1 comment

Comments

@faiq-naseem
Copy link

Can you show how to implement TreeSelect and pass options?

@FaZeRs
Copy link

FaZeRs commented Mar 1, 2020

I use kalnoy/nestedset to create nested set.

Inside Resource

public function fields(Request $request)
{
	$nodes = Category::get()->toTree();
	$categories = $this->mapCategories($nodes);
	return [
 		TreeSelect::make('Parent id')->options($categories)->onlyOnForms(),
        BelongsTo::make('Category', 'parent')->searchable()->hideWhenCreating()->hideWhenUpdating(),
		HasMany::make('Category', 'children')
}

private function mapCategories($nodes)
{
	$categories = [];
	foreach($nodes as $key => $node) {
		$categories[] = [
			'id' => $node->id,
			'label' => $node->title,
			'children' => mapCategories($node->children)
		];
	}
    return collect($categories);
}

I created PR to fix missing laravel nova mixins
#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants