forked from aslan/applicant-site
prodV1 #2
|
@ -7,6 +7,7 @@ use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
|
|||
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
|
||||
use App\Models\Department;
|
||||
use App\Models\Direction;
|
||||
use App\Models\EducationLevel;
|
||||
use App\Models\Faculty;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
@ -23,8 +24,9 @@ class DirectionController extends Controller
|
|||
|
||||
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$levels = EducationLevel::pluck('name', 'id');
|
||||
$departments = Department::pluck('name', 'id');
|
||||
return view('admin.catalog.direction.create', compact('departments'));
|
||||
return view('admin.catalog.direction.create', compact('departments', 'levels'));
|
||||
}
|
||||
|
||||
public function store(StoreDirectionRequest $request): RedirectResponse
|
||||
|
@ -36,6 +38,8 @@ class DirectionController extends Controller
|
|||
$direction->description = $validated['description'];
|
||||
$direction->position = $validated['position'];
|
||||
$direction->slug = $validated['slug'];
|
||||
$direction->code = $validated['code'];
|
||||
$direction->education_level_id = $validated['education_level_id'];
|
||||
$direction->department_id = $validated['department_id'];
|
||||
$direction->save();
|
||||
|
||||
|
@ -60,18 +64,22 @@ class DirectionController extends Controller
|
|||
|
||||
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$levels = EducationLevel::pluck('name', 'id');
|
||||
$departments = Department::pluck('name', 'id');
|
||||
return view('admin.catalog.direction.edit', compact('direction', 'departments'));
|
||||
return view('admin.catalog.direction.edit', compact('direction', 'departments', 'levels'));
|
||||
}
|
||||
|
||||
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$direction = new Direction();
|
||||
$direction->name = $validated['name'];
|
||||
$direction->description = $validated['description'];
|
||||
$direction->position = $validated['position'];
|
||||
$direction->slug = $validated['slug'];
|
||||
$direction->code = $validated['code'];
|
||||
$direction->education_level_id = $validated['education_level_id'];
|
||||
$direction->department_id = $validated['department_id'];
|
||||
$direction->save();
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ class StoreDirectionRequest extends FormRequest
|
|||
'name' => 'required|string|max:255|unique:directions,name',
|
||||
'description' => 'string',
|
||||
'slug' => 'required|string',
|
||||
'code' => 'required|string',
|
||||
'education_level_id' => 'required|int',
|
||||
'department_id' => 'required|int'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ class UpdateDirectionRequest extends FormRequest
|
|||
'description' => 'string',
|
||||
'department_id' => 'int|required',
|
||||
'slug' => 'required|string',
|
||||
'code' => 'required|string',
|
||||
'education_level_id' => 'required|int',
|
||||
'name' => [
|
||||
'required',
|
||||
'string',
|
||||
|
|
|
@ -15,10 +15,17 @@ class Direction extends Model
|
|||
'name',
|
||||
'description',
|
||||
'position',
|
||||
'slug',
|
||||
'code',
|
||||
];
|
||||
|
||||
public function department(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Department::class);
|
||||
}
|
||||
|
||||
public function educationLevel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EducationLevel::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,10 @@ class DirectionFactory extends Factory
|
|||
'name' => fake()->name(),
|
||||
'description' => fake()->text(),
|
||||
'slug' => fake()->slug(),
|
||||
'code' => fake()->text(50),
|
||||
'position' => fake()->randomDigit(),
|
||||
'department_id' => 1,
|
||||
'education_level_id' => 1
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,11 @@ return new class extends Migration
|
|||
$table->id();
|
||||
$table->string('name');
|
||||
$table->text('description');
|
||||
$table->string('code');
|
||||
$table->integer('position');
|
||||
$table->string('slug');
|
||||
$table->foreignId('department_id')->constrained('departments');
|
||||
$table->foreignId('education_level_id')->constrained('education_levels');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,11 +4,40 @@ namespace Database\Seeders;
|
|||
|
||||
use App\Models\Direction;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DirectionSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
Direction::factory(3)->create();
|
||||
DB::table('directions')->insert([
|
||||
[
|
||||
'name' => 'Юриспруденция',
|
||||
'description' => 'Юриспруденция',
|
||||
'slug' => 'jurisprudence',
|
||||
'code' => '40.03.01',
|
||||
'position' => 1,
|
||||
'department_id' => 1,
|
||||
'education_level_id' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'фармация',
|
||||
'description' => 'фармация',
|
||||
'slug' => 'pharmacy',
|
||||
'code' => '33.05.01',
|
||||
'position' => 2,
|
||||
'department_id' => 1,
|
||||
'education_level_id' => 2,
|
||||
],
|
||||
[
|
||||
'name' => 'строительство',
|
||||
'description' => 'строительство',
|
||||
'slug' => 'construction',
|
||||
'code' => '08.04.01',
|
||||
'position' => 3,
|
||||
'department_id' => 1,
|
||||
'education_level_id' => 3,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название') }}
|
||||
{{ Form::label('code', 'Название') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('name', '', ['class' => 'form-control']) }}
|
||||
{{ Form::text('code', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
{{ $errors->first('code') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
|||
@endif
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
{{ Form::label('department_id', 'Кафедры') }}
|
||||
{{ Form::label('department_id', 'Кафедра') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::select('department_id', $departments, null, ['class' => 'form-select']) }}
|
||||
|
@ -52,6 +52,19 @@
|
|||
{{ $errors->first('department_id') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('education_level_id', 'Увовень образования') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::select('education_level_id', $levels, null, ['class' => 'form-select']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('education_level_id') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
</div>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class=""> Создать кафедру</h1>
|
||||
<h1 class="">Изменить направление</h1>
|
||||
{{ Form::open(['url' => route('departments.update', $direction), 'method' => 'PATCH', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div class="mt-3">
|
||||
|
@ -43,16 +43,29 @@
|
|||
@endif
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
{{ Form::label('educational_institution_id', 'Факультет') }}
|
||||
{{ Form::label('department_id', 'Факультет') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::select('faculty_id', $departments, $direction->department->id, ['class' => 'form-select']) }}
|
||||
{{ Form::select('department_id', $departments, $direction->department->id, ['class' => 'form-select']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('educational_institution_id') }}
|
||||
{{ $errors->first('department_id') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('education_level_id', 'Увовень образования') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::select('education_level_id', $levels, $direction->educationLevel->id, ['class' => 'form-select']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('education_level_id') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
</div>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<th scope="col">Описание</th>
|
||||
<th scope="col">URL</th>
|
||||
<th scope="col">Кафедра</th>
|
||||
<th scope="col">Уровень образования</th>
|
||||
<th scope="col">действия</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
|
@ -27,6 +28,7 @@
|
|||
<td>{{ Str::words($direction->description, 10, '...') }}</td>
|
||||
<td>{{ $direction->slug }}</td>
|
||||
<td>{{ $direction->department->name }}</td>
|
||||
<td>{{ $direction->educationLevel->name }}</td>
|
||||
<td>
|
||||
<a href="{{ route("directions.edit", $direction) }}"
|
||||
class="btn btn-secondary">редактировать</a>
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
<p>{{ $direction->slug }}</p>
|
||||
<h2>Кафедра</h2>
|
||||
<p><a href="{{ route('departments.show', $department) }}">{{ $department->name }}</a></p>
|
||||
<h2>Уровень Образования</h2>
|
||||
<p><a href="{{ route('education_levels.show', $direction->educationLevel) }}">{{ $direction->educationLevel->name }}</a></p>
|
||||
</div>
|
||||
@endauth
|
||||
@endsection
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Tests\Feature\admin\catalog;
|
|||
use App\Models\Department;
|
||||
use App\Models\Direction;
|
||||
use App\Models\EducationalInstitution;
|
||||
use App\Models\EducationLevel;
|
||||
use App\Models\Faculty;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
@ -19,6 +20,7 @@ class DepartmentTest extends TestCase
|
|||
parent::setUp();
|
||||
EducationalInstitution::factory()->create();
|
||||
Faculty::factory()->create();
|
||||
EducationLevel::factory()->create();
|
||||
|
||||
$this->department = Department::factory()->create();
|
||||
$this->data = Department::factory()->make()->only([
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Tests\Feature\admin\catalog;
|
|||
use App\Models\Department;
|
||||
use App\Models\Direction;
|
||||
use App\Models\EducationalInstitution;
|
||||
use App\Models\EducationLevel;
|
||||
use App\Models\Faculty;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
@ -20,13 +21,16 @@ class DirectionTest extends TestCase
|
|||
EducationalInstitution::factory()->create();
|
||||
Faculty::factory()->create();
|
||||
Department::factory()->create();
|
||||
EducationLevel::factory()->create();
|
||||
|
||||
$this->direction = Direction::factory()->create();
|
||||
$this->data = Direction::factory()->make()->only([
|
||||
'position',
|
||||
'name',
|
||||
'description',
|
||||
'code',
|
||||
'slug',
|
||||
'education_level_id',
|
||||
'department_id',
|
||||
]);
|
||||
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\admin\catalog;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\Direction;
|
||||
use App\Models\EducationalInstitution;
|
||||
use App\Models\EducationLevel;
|
||||
use App\Models\Faculty;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EducationLevelTest extends TestCase
|
||||
{
|
||||
private User $user;
|
||||
private Direction $direction;
|
||||
private EducationLevel $level;
|
||||
private array $data;
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
EducationalInstitution::factory()->create();
|
||||
Faculty::factory()->create();
|
||||
Department::factory()->create();
|
||||
$this->level = EducationLevel::factory()->create();
|
||||
|
||||
$this->direction = Direction::factory()->create();
|
||||
$this->data = EducationLevel::factory()->make()->only([
|
||||
'name',
|
||||
'description',
|
||||
'slug',
|
||||
]);
|
||||
|
||||
$this->user = User::factory()->create([
|
||||
'name' => 'admin',
|
||||
'email' => 'test@example.com',
|
||||
'password' => 123456
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIndexEducationLevelsPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('education_levels.index'));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function testCreateEducationLevelPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('education_levels.create'));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function testStoreEducationLevel(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->post(route('education_levels.store', $this->data));
|
||||
|
||||
$response->assertRedirect(route('education_levels.index'));
|
||||
|
||||
$this->assertDatabaseHas('education_levels', $this->data);
|
||||
}
|
||||
|
||||
public function testShowEducationLevelPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('education_levels.show', $this->level));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function testEditEducationLevelPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('education_levels.edit', $this->level));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function testUpdateEducationLevel(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->patch(route('education_levels.update', $this->level), $this->data);
|
||||
|
||||
$response->assertRedirect(route('education_levels.index'));
|
||||
|
||||
$this->assertDatabaseHas('education_levels', $this->data);
|
||||
}
|
||||
|
||||
public function testDestroyEducationLevel(): void
|
||||
{
|
||||
$this->direction->delete();
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->delete(route('education_levels.destroy', $this->level));
|
||||
|
||||
$response->assertRedirect(route('education_levels.index'));
|
||||
|
||||
$this->assertDatabaseMissing('education_levels', $this->level->toArray());
|
||||
}
|
||||
|
||||
public function testNotDestroyEducationLevel(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->delete(route('education_levels.destroy', $this->level));
|
||||
|
||||
$response->assertStatus(302);
|
||||
|
||||
$this->assertDatabaseHas('education_levels', $this->level->only(['name', 'slug']));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue