feat: add migration handling for navbar_links table in NavbarManager to ensure navigation links are available and prevent errors
This commit is contained in:
@@ -11,6 +11,7 @@ use Paymenter\Extensions\Others\NavbarManager\Models\NavbarLink;
|
|||||||
|
|
||||||
class NavbarManager extends Extension
|
class NavbarManager extends Extension
|
||||||
{
|
{
|
||||||
|
private static bool $migrationAttempted = false;
|
||||||
public function getConfig($values = [])
|
public function getConfig($values = [])
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -74,6 +75,30 @@ class NavbarManager extends Extension
|
|||||||
private function getNavigationLinks($type)
|
private function getNavigationLinks($type)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
if (!\Schema::hasTable('navbar_links')) {
|
||||||
|
if (!self::$migrationAttempted) {
|
||||||
|
self::$migrationAttempted = true;
|
||||||
|
try {
|
||||||
|
Artisan::call('migrate', [
|
||||||
|
'--path' => 'extensions/Others/NavbarManager/database/migrations',
|
||||||
|
'--force' => true,
|
||||||
|
]);
|
||||||
|
} catch (\Exception $migrationException) {
|
||||||
|
\Log::error('NavbarManager: Failed to run migrations', [
|
||||||
|
'error' => $migrationException->getMessage(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table still missing, skip navigation injection to prevent 500s
|
||||||
|
if (!\Schema::hasTable('navbar_links')) {
|
||||||
|
\Log::warning('NavbarManager: navbar_links table missing. Skipping navigation injection.', [
|
||||||
|
'type' => $type,
|
||||||
|
]);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$links = NavbarLink::where('type', $type)
|
$links = NavbarLink::where('type', $type)
|
||||||
->where('is_active', true)
|
->where('is_active', true)
|
||||||
->whereNull('parent_id') // Only get top-level links
|
->whereNull('parent_id') // Only get top-level links
|
||||||
|
|||||||
Reference in New Issue
Block a user