where('slug', $tableName)->first(); if ($typeBySlug) { return $typeBySlug->slug; } // Priority 2: Check types.table_name explicitly (best match for API table params) if (Schema::hasColumn('types', 'table_name')) { $typeByTableName = DB::table('types') ->where('table_name', $tableName) ->first(); if ($typeByTableName) { return $typeByTableName->slug; } } // Priority 3: Read blade files to find $tableName definition (like in MobileTypeController) $types = DB::table('types')->get(); foreach ($types as $type) { $bladePath = resource_path("views/admin/type/{$type->slug}.blade.php"); if (File::exists($bladePath)) { $content = File::get($bladePath); if (preg_match('/\$tableName\s*=\s*["\']([^"\']+)["\']\s*;/', $content, $matches)) { $foundTable = $matches[1]; if ($foundTable === $tableName) { return $type->slug; } } } } // Priority 4: Try some simple naming conventions if (\Illuminate\Support\Str::contains($tableName, '_')) { $guessedSlug = str_replace('_', '-', $tableName); $typeByGuessedSlug = DB::table('types')->where('slug', $guessedSlug)->first(); if ($typeByGuessedSlug) { return $typeByGuessedSlug->slug; } $guessedSlugSingular = \Illuminate\Support\Str::slug(\Illuminate\Support\Str::singular($tableName)); $typeByGuessedSingular = DB::table('types')->where('slug', $guessedSlugSingular)->first(); if ($typeByGuessedSingular) { return $typeByGuessedSingular->slug; } } // Fallback: return the original string return $tableName; }); } }