Skip to content

Commit c67299b

Browse files
committed
Merge branch '50-templates-improvements' into 'master'
Resolve "Оптимизировать шаблоны" See merge request components/laravel-entity-generator!67
2 parents 95bc32e + 58f465f commit c67299b

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

stubs/migration.blade.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use Illuminate\Support\Facades\Schema;
2-
use Illuminate\Database\Schema\Blueprint;
31
use Illuminate\Database\Migrations\Migration;
4-
use Illuminate\Support\Facades\DB;
2+
use Illuminate\Database\Schema\Blueprint;
3+
use Illuminate\Support\Facades\Schema;
54
use RonasIT\Support\Traits\MigrationTrait;
65

76
class {{$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
}

stubs/repository.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
namespace App\Repositories;
22

3+
use App\Models\{{$entity}};
4+
@if(!empty($fields['json']))
35
use Illuminate\Support\Arr;
6+
@endif
47
use RonasIT\Support\Repositories\BaseRepository;
5-
use App\Models\{{$entity}};
68
{{--
79
Laravel inserts two spaces between @property and type, so we are forced
810
to use hack here to preserve one space

0 commit comments

Comments
 (0)