1- use Illuminate\Support\Facades\Schema;
2- use Illuminate\Database\Schema\Blueprint;
31use Illuminate\Database\Migrations\Migration;
4- use Illuminate\Support\Facades\DB;
2+ use Illuminate\Database\Schema\Blueprint;
3+ use Illuminate\Support\Facades\Schema;
54use RonasIT\Support\Traits\MigrationTrait;
65
76class {{ $class } } CreateTable extends Migration
@@ -10,7 +9,17 @@ class {{$class}}CreateTable extends Migration
109
1110 public function up()
1211 {
12+ @if (! empty ($relations [' belongsToMany' ]) || ! empty ($relations [' belongsTo' ]) || ! empty ($relations [' hasOne' ]) || ! empty ($relations [' hasMany' ]) )
1313 $this->createTable();
14+ @else
15+ Schema::create('{{ \Illuminate \Support \Str:: plural (\Illuminate \Support \Str:: snake ($entity )) } } ', function (Blueprint $table) {
16+ $table->increments('id');
17+ @foreach ($table as $row )
18+ {!! $row ! !}
19+ @endforeach
20+ $table->timestamps();
21+ });
22+ @endif
1423@foreach ($relations [' belongsToMany' ] as $relation )
1524
1625 $this->createBridgeTable('{{ $entity } } ', '{{ $relation } } ');
@@ -43,17 +52,19 @@ public function down()
4352 $this->dropBridgeTable('{{ $entity } } ', '{{ $relation } } ');
4453
4554@endforeach
46- Schema::drop ('{{ \Illuminate \Support \Str:: plural (\Illuminate \Support \Str:: snake ($entity )) } } ');
55+ Schema::dropIfExists ('{{ \Illuminate \Support \Str:: plural (\Illuminate \Support \Str:: snake ($entity )) } } ');
4756 }
57+ @if (! empty ($relations [' belongsToMany' ]) || ! empty ($relations [' belongsTo' ]) || ! empty ($relations [' hasOne' ]) || ! empty ($relations [' hasMany' ]) )
4858
4959 public function createTable()
5060 {
5161 Schema::create('{{ \Illuminate \Support \Str:: plural (\Illuminate \Support \Str:: snake ($entity )) } } ', function (Blueprint $table) {
5262 $table->increments('id');
53- $table->timestamps();
5463@foreach ($table as $row )
5564 {!! $row ! !}
5665@endforeach
66+ $table->timestamps();
5767 });
5868 }
69+ @endif
5970}
0 commit comments