🆙 Fix code in somephp files an refactored and deleted deprecated code 🆙

This commit is contained in:
Remco
2026-01-19 17:25:31 +01:00
parent 3238cdb8e7
commit 6736e8fe60
9 changed files with 145 additions and 92 deletions
+26 -5
View File
@@ -37,12 +37,33 @@ if (! function_exists('strLimit')) {
if (! function_exists('findMigration')) {
function findMigration(string $tableName): string
{
foreach (glob(database_path('migrations/*.php')) as $filename) {
$content = file_get_contents($filename);
if ($content !== false && str_contains($content, "Schema::create('$tableName'")) {
return basename($filename);
}
static $cache = [];
if (isset($cache[$tableName])) {
return $cache[$tableName];
}
$migrationsPath = database_path('migrations');
if (! is_dir($migrationsPath)) {
return '';
}
try {
$files = new \DirectoryIterator($migrationsPath);
foreach ($files as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$content = @file_get_contents($file->getPathname());
if ($content !== false && str_contains($content, "Schema::create('$tableName'")) {
$cache[$tableName] = $file->getFilename();
return $file->getFilename();
}
}
}
} catch (\Exception $e) {
\Illuminate\Support\Facades\Log::error("Error finding migration for table {$tableName}: {$e->getMessage()}");
}
$cache[$tableName] = '';
return '';
}
}