Skip to content

Conversation

@stefket
Copy link
Contributor

@stefket stefket commented Sep 15, 2025

This PR introduces the ability to use the SelectTree component without requiring an Eloquent relationship.

Previously, the component only worked when bound to a model relationship via ->relationship(...). However, there are valid use cases where no relationship exists — for example, when selecting navigation points to insert links inside a RichText editor.

To support this, a new ->query(...) method has been added. This allows developers to provide a custom query directly, enabling the SelectTree component to be used more flexibly across different scenarios.

Key changes:

  • Added ->query() method as an alternative to ->relationship(...).
  • Ensures that the component can still be used in contexts where no model relationship is defined.
  • Keeps backward compatibility with existing ->relationship(...) usage.

Example usage:

SelectTree::make('category_id')
    ->query(fn() => Category::query(), 'name', 'parent_id')

This enhancement makes SelectTree more versatile and applicable beyond relationship-driven use cases.

@CodeWithDennis
Copy link
Owner

This is cool! I will try to find some time and spin up a new project making sure nothing breaks.

@gp-lnuff
Copy link
Contributor

This would be a very welcome addition, as a workaround I've been using self-referencing relationships with target "group" records and scoping them out of my resources.

Copy link
Owner

@CodeWithDennis CodeWithDennis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@CodeWithDennis CodeWithDennis merged commit 9d9f1ee into CodeWithDennis:4.x Sep 19, 2025
1 check passed
@stefket
Copy link
Contributor Author

stefket commented Sep 19, 2025

Thanks for merging! :-)

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

Successfully merging this pull request may close these issues.

3 participants