It would be nice and more aligned with how the [Migration Order](../tree/master/readme.md#Migration Order) natively works in Laravel, to have an Attribute automatically created, containing the date of the migration creation:
[!NOTE]
Each migration filename contains a timestamp that allows Laravel to determine the order of the migrations
use Bastinald\LaravelAutomaticMigrations\Attributes\MigrationScaffoldedAt;
class MyModel extends Model
{
#[MigrationScaffoldedAt('2024_01_10_123456')]
public function migration(Blueprint $table)
{
$table->id();
$table->string('name');
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
}
}
This would then be implemented something like this:
<?php
namespace Bastinald\LaravelAutomaticMigrations\Commands;
[…]
use Bastinald\LaravelAutomaticMigrations\Attributes\MigrationScaffoldedAt;
use ReflectionClass;
class MigrateAutoCommand extends Command
{
[…]
private function handleAutomaticMigrations()
{
[…]
foreach ((new Finder)->in($path) as $model) {
[…]
if (method_exists($model, 'migration')) {
$object = app($model);
$reflection = new ReflectionClass($model);
$attribute = $reflection->getAttributes(MigrationScaffoldedAt::class)[0];
$scaffoldingDate = $attribute->getArguments()[0];
$models->push([
'object' => $object,
'order' => $object->migrationOrder ?? $scaffoldingDate ?? 0
]);
}
}
foreach ($models->sortBy('order') as $model) {
$this->migrate($model['object']);
}
}
It would be nice and more aligned with how the [Migration Order](../tree/master/readme.md#Migration Order) natively works in Laravel, to have an
Attribute
automatically created, containing the date of the migration creation:This would then be implemented something like this: