Don't allow navigating to dashboard pages for models that aren't listed in the menu

This commit is contained in:
Kevin MacMartin 2021-07-29 17:37:33 -04:00
parent 4abcbe879e
commit e0ffe81e51

View file

@ -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) {