Skip to content

Commit

Permalink
Eager load Menu Items translations (#4720)
Browse files Browse the repository at this point in the history
* Eager load Menu Items translations

When multilingual is enabled this PR removes one query for each menu item and adds one query for each nested group.

* removed eagerload for non admin menu

because it's already done inside the template -_-'

Co-authored-by: Eric Fletcher <fletch3555@users.noreply.github.com>
  • Loading branch information
MrCrayon and fletch3555 committed Feb 17, 2020
1 parent e6d96dd commit 51876b0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Models/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public function removeMenuFromCache()

private static function processItems($items)
{
// Eagerload Translations
if (config('voyager.multilingual.enabled')) {
$items->load('translations');
}

$items = $items->transform(function ($item) {
// Translate title
$item->title = $item->getTranslatedAttribute('title');
Expand Down

0 comments on commit 51876b0

Please sign in to comment.