-
Apologies if this is answered elsewhere. I'm fairly new to laravel as well as twill and couldn't find an answer in the documentation. I have a model called page on a test site and I'm loading a collection of them on every page to use in the menu. They have slugs and I've discovered by using Debug Bar that each related slug is being fetched with a separate query. I tried adding the 'page_slugs' database table to the view with My code in
Again, I've probably missed something painfully obvious, but am just starting to get my head round how laravel lazy_loads tables. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @BezPowell the relationship you are trying to eager load is named "slugs", not "page_slugs". You're on the right path by using with() on your query. |
Beta Was this translation helpful? Give feedback.
-
However, you don't need to load all slugs (as in inactive ones too), so you can also limit the eager loading with with() to only load active ones for the current locale. See https://laravel.com/docs/10.x/eloquent-relationships#constraining-eager-loads. |
Beta Was this translation helpful? Give feedback.
Hi @BezPowell the relationship you are trying to eager load is named "slugs", not "page_slugs". You're on the right path by using with() on your query.