diff --git a/app/Dashboard.php b/app/Dashboard.php index 09a070d..7efada7 100644 --- a/app/Dashboard.php +++ b/app/Dashboard.php @@ -72,7 +72,32 @@ class Dashboard { $model_name = ucfirst($model); - if (file_exists(app_path() . '/Models/' . $model_name . '.php')) { + // Ensure the model has been declared in the menu + $model_in_menu = false; + + foreach (self::$menu as $menu_item) { + if (array_key_exists('submenu', $menu_item)) { + // Check each item if this is a submenu + foreach ($menu_item['submenu'] as $submenu_item) { + if ($submenu_item['model'] == $model) { + $model_in_menu = true; + break; + } + } + } else { + // Check the menu item + if ($menu_item['model'] == $model) { + $model_in_menu = true; + } + } + + // Don't bother continuing if we've already confirmed it's in the menu + if ($model_in_menu) { + break; + } + } + + if ($model_in_menu && file_exists(app_path() . '/Models/' . $model_name . '.php')) { $model_class = 'App\\Models\\' . $model_name; if ($type != null && $type != $model_class::$dashboard_type) {