Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save timramseyjr/7a20da9f702aede76d2b5a85b2e11fcd to your computer and use it in GitHub Desktop.
Save timramseyjr/7a20da9f702aede76d2b5a85b2e11fcd to your computer and use it in GitHub Desktop.
Publish migrations as assets instead of loading them.
<?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