When creating a migration via make:migration, the table name is hardcoded in several places. Also, there is no check in the "up" method that the table has not been created yet (which is strange, because in "down" the presence of the table is checked). As a result, when creating a new migration, you have to eliminate these points yourself every time. I really want these things to be out of the box.
Now:
public function up(): void
{
Schema::create('mytable', function (Blueprint $table) {
...
public function down(): void
{
Schema::dropIfExists('mytable');
...
My way:
public const TABLENAME = 'mytable';
public function up(): void
{
if (Schema::hasTable(self::TABLENAME)) {
return;
}
Schema::create(self::TABLENAME, function (Blueprint $table) {
...
}
public function down(): void
{
Schema::dropIfExists(self::TABLENAME);
Benefit - is subjectively convenient
This does not break any existing features as it does not affect logic. These are minor edits in migration templates. The tests have been updated according to the new templates
When creating a migration via make:migration, the table name is hardcoded in several places. Also, there is no check in the "up" method that the table has not been created yet (which is strange, because in "down" the presence of the table is checked). As a result, when creating a new migration, you have to eliminate these points yourself every time. I really want these things to be out of the box.
Now:
My way:
Benefit - is subjectively convenient This does not break any existing features as it does not affect logic. These are minor edits in migration templates. The tests have been updated according to the new templates