reorganization DirectionProfile and Direction to many to many

This commit is contained in:
aslan 2024-02-29 18:01:23 +03:00
parent bd8bb7e059
commit 9d7f531ac8
9 changed files with 7 additions and 42 deletions

View File

@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class DirectionProfile extends Model class DirectionProfile extends Model
{ {
@ -16,11 +17,10 @@ class DirectionProfile extends Model
'description', 'description',
'slug', 'slug',
'position', 'position',
'direction_id'
]; ];
public function direction(): BelongsTo public function direction(): BelongsToMany
{ {
return $this->belongsTo(Direction::class); return $this->belongsToMany(Direction::class);
} }
} }

View File

@ -13,7 +13,6 @@ class DirectionProfileFactory extends Factory
'description' => fake()->text(), 'description' => fake()->text(),
'slug' => fake()->slug(), 'slug' => fake()->slug(),
'position' => 1, 'position' => 1,
'direction_id' => 1,
]; ];
} }
} }

View File

@ -17,7 +17,6 @@ return new class extends Migration
$table->text('description')->nullable(); $table->text('description')->nullable();
$table->string('slug'); $table->string('slug');
$table->string('position'); $table->string('position');
$table->foreignId('direction_id')->constrained('directions');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -11,12 +11,10 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::create('place_types', function (Blueprint $table) { Schema::create('direction_direction_profile', function (Blueprint $table) {
$table->id(); $table->id();
$table->integer('position'); $table->foreignId('direction_id')->constrained('directions');
$table->string('name'); $table->foreignId('direction_profile_id')->constrained('direction_profiles');
$table->text('description')->nullable();
$table->string('slug');
$table->timestamps(); $table->timestamps();
}); });
} }
@ -26,6 +24,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfExists('place_types'); Schema::dropIfExists('direction_direction_profile');
} }
}; };

View File

@ -16,21 +16,18 @@ class DirectionProfileSeeder extends Seeder
'description' => 'Государственно-правовой профиль', 'description' => 'Государственно-правовой профиль',
'slug' => 'the-state-legal', 'slug' => 'the-state-legal',
'position' => 1, 'position' => 1,
'direction_id' => 1,
], ],
[ [
'name' => 'Условно-правовой', 'name' => 'Условно-правовой',
'description' => 'Условно-правовой профиль', 'description' => 'Условно-правовой профиль',
'slug' => 'probationary-profile', 'slug' => 'probationary-profile',
'position' => 2, 'position' => 2,
'direction_id' => 1,
], ],
[ [
'name' => 'Цифровой Юрист', 'name' => 'Цифровой Юрист',
'description' => 'Цифровой Юрист профиль', 'description' => 'Цифровой Юрист профиль',
'slug' => 'digital-lawyer', 'slug' => 'digital-lawyer',
'position' => 3, 'position' => 3,
'direction_id' => 1,
], ],
]); ]);
} }

View File

@ -18,18 +18,6 @@
@endif @endif
</div> </div>
<div class="mt-3">
{{ Form::label('direction_id', 'Направление подготовки') }}
</div>
<div class="mt-1">
{{ Form::select('direction_id', $directions, null, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('direction_id') }}
@endif
</div>
<div class="mt-3"> <div class="mt-3">
{{ Form::label('description', 'Описание') }} {{ Form::label('description', 'Описание') }}
</div> </div>

View File

@ -18,18 +18,6 @@
@endif @endif
</div> </div>
<div class="mt-3">
{{ Form::label('direction_id', 'Направление подготовки') }}
</div>
<div class="mt-1">
{{ Form::select('direction_id', $directions, $directionProfile->direction->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('direction_id') }}
@endif
</div>
<div class="mt-3"> <div class="mt-3">
{{ Form::label('description', 'Описание') }} {{ Form::label('description', 'Описание') }}
</div> </div>

View File

@ -10,7 +10,6 @@
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left"> <thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
<tr> <tr>
<th scope="col">Название</th> <th scope="col">Название</th>
<th scope="col">Направление подготовки</th>
<th scope="col">Описание</th> <th scope="col">Описание</th>
<th scope="col">Позиция</th> <th scope="col">Позиция</th>
<th scope="col">URL</th> <th scope="col">URL</th>
@ -22,7 +21,6 @@
@foreach($directionProfiles as $directionProfile) @foreach($directionProfiles as $directionProfile)
<tr class=""> <tr class="">
<td><a href="{{ route('direction_profiles.show', $directionProfile) }}">{{ $directionProfile->name }}</a></td> <td><a href="{{ route('direction_profiles.show', $directionProfile) }}">{{ $directionProfile->name }}</a></td>
<td><a href="{{ route('directions.show', $directionProfile->direction) }}">{{ $directionProfile->direction->name }}</a></td>
<td>{{ Str::words($directionProfile->description, 10, '...') }}</td> <td>{{ Str::words($directionProfile->description, 10, '...') }}</td>
<td>{{ $directionProfile->position }}</td> <td>{{ $directionProfile->position }}</td>
<td>{{ $directionProfile->slug }}</td> <td>{{ $directionProfile->slug }}</td>

View File

@ -4,8 +4,6 @@
<div class="container mt-4"> <div class="container mt-4">
<h2>Название</h2> <h2>Название</h2>
<p>{{ $directionProfile->name }}</p> <p>{{ $directionProfile->name }}</p>
<h2>Направление подготовки</h2>
<p><a href="{{ route('directions.show', $directionProfile->direction) }}">{{ $directionProfile->direction->name }}</a></p>
<h2>Описание</h2> <h2>Описание</h2>
<p>{{ $directionProfile->description }}</p> <p>{{ $directionProfile->description }}</p>
<h2>Позиция</h2> <h2>Позиция</h2>