Last active
August 8, 2022 16:01
-
-
Save DarkGhostHunter/1a2a4f26f6f571d815581cc1b353c756 to your computer and use it in GitHub Desktop.
Publish migrations as assets instead of loading them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\Package; | |
use Generator; | |
use Illuminate\Support\Str; | |
trait PublishesMigrations | |
{ | |
/** | |
* Searches migrations and publishes them as assets. | |
* | |
* @param string $directory | |
* | |
* @return void | |
*/ | |
protected function registerMigrations(string $directory): void | |
{ | |
if ($this->app->runningInConsole()) { | |
$generator = function(string $directory): Generator { | |
foreach ($this->app->make('files')->allFiles($directory) as $file) { | |
yield $file->getPathname() => $this->app->databasePath( | |
'migrations/' . now()->format('Y_m_d_His') . Str::after($file->getFilename(), '00_00_00_000000') | |
); | |
} | |
}; | |
$this->publishes(iterator_to_array($generator($directory)), 'migrations'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment