2024-08-09 08:23:03 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Migrations\Migrator;
|
|
|
|
|
|
|
|
|
|
trait CheckMigrationsTrait
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Checks if the migrations have finished running by comparing the last migration file.
|
|
|
|
|
*/
|
|
|
|
|
protected function hasCompletedMigrations(): bool
|
|
|
|
|
{
|
|
|
|
|
/** @var Migrator $migrator */
|
2025-03-03 14:41:19 -05:00
|
|
|
$migrator = app()->make('migrator'); // @phpstan-ignore myCustomRules.forbiddenGlobalFunctions
|
2024-08-09 08:23:03 +02:00
|
|
|
|
|
|
|
|
$files = $migrator->getMigrationFiles(database_path('migrations'));
|
|
|
|
|
|
|
|
|
|
if (!$migrator->repositoryExists()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (array_diff(array_keys($files), $migrator->getRepository()->getRan())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|