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

Prevent LazyLoadingViolationException when using strict mode #51

Merged
merged 2 commits into from
Nov 10, 2024

Conversation

Senexis
Copy link
Contributor

@Senexis Senexis commented Nov 9, 2024

Currently when using the package in conjunction with strict models, editing a menu will fail due to a LazyLoadingViolationException since the linkable is not eager loaded with the MenuItems. This pull request fixes that, making the package compatible with strict mode as far as I can tell.

Although usually the use of $with is discouraged, it seems the MenuItem class heavily relies on the relationship anywhere it is used. In the future, this could be improved by introducing specific ->with() calls on the various queries, but this should go a long way and shouldn't be too egregious.

The following should now work in the app's service provider:

use Illuminate\Database\Eloquent\Model;

Model::shouldBeStrict();

Copy link
Owner

@datlechin datlechin left a comment

Choose a reason for hiding this comment

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

Thank you

@datlechin datlechin merged commit 6859270 into datlechin:main Nov 10, 2024
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.

2 participants