add ExaminationType resource
This commit is contained in:
parent
d9362477c2
commit
1070d543c5
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\admin\Catalog\Direction;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\admin\Catalog\Direction\StoreExaminationTypeRequest;
|
||||
use App\Http\Requests\admin\Catalog\Direction\UpdateExaminationTypeRequest;
|
||||
use App\Models\ExaminationType;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class ExaminationTypeController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$types = ExaminationType::all();
|
||||
return view('admin.catalog.direction.examination_type.index', compact('types'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
return view('admin.catalog.direction.examination_type.create');
|
||||
}
|
||||
|
||||
public function store(StoreExaminationTypeRequest $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$type = new ExaminationType();
|
||||
$type->name = $validated['name'];
|
||||
$type->description = $validated['description'];
|
||||
$type->slug = $validated['slug'];
|
||||
$type->position = $validated['position'];
|
||||
$type->save();
|
||||
|
||||
return redirect()->route('examination_types.index');
|
||||
}
|
||||
|
||||
public function show(ExaminationType $examinationType): View
|
||||
{
|
||||
return view('admin.catalog.direction.examination_type.show', compact('examinationType'));
|
||||
}
|
||||
|
||||
public function edit(ExaminationType $examinationType): View
|
||||
{
|
||||
return view('admin.catalog.direction.examination_type.edit', compact('examinationType'));
|
||||
}
|
||||
|
||||
public function update(UpdateExaminationTypeRequest $request, ExaminationType $examinationType): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$examinationType->name = $validated['name'];
|
||||
$examinationType->description = $validated['description'];
|
||||
$examinationType->slug = $validated['slug'];
|
||||
$examinationType->position = $validated['position'];
|
||||
$examinationType->save();
|
||||
|
||||
return redirect()->route('examination_types.index');
|
||||
}
|
||||
|
||||
public function destroy(ExaminationType $examinationType): RedirectResponse
|
||||
{
|
||||
if ($examinationType->entranceExaminations()->exists()) {
|
||||
return back();
|
||||
}
|
||||
$examinationType->delete();
|
||||
return redirect()->route('examination_types.index');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\admin\Catalog\Direction;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreExaminationTypeRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'position' => 'required|int|numeric|max:255',
|
||||
'name' => 'required|string|max:255|unique:examination_types,name',
|
||||
'description' => 'string',
|
||||
'slug' => 'required|string|max:255|unique:examination_types,slug',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\admin\Catalog\Direction;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateExaminationTypeRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'position' => 'required|int|numeric|max:255',
|
||||
'description' => 'string',
|
||||
'slug' => [
|
||||
'string',
|
||||
'required',
|
||||
'max:255',
|
||||
"unique:examination_types,slug,{$this->examination_type->id}",
|
||||
],
|
||||
'name' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
"unique:examination_types,name,{$this->examination_type->id}",
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ExaminationType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'description',
|
||||
'slug',
|
||||
'position',
|
||||
];
|
||||
|
||||
public function entranceExaminations(): HasMany
|
||||
{
|
||||
return $this->hasMany('App\Models\EntranceExamination', 'examination_type_id');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ExaminationTypeFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'description' => fake()->text(),
|
||||
'slug' => fake()->slug(),
|
||||
'position' => fake()->randomDigit(),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('examination_types', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('position');
|
||||
$table->string('name');
|
||||
$table->text('description')->nullable();
|
||||
$table->string('slug');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('examination_types');
|
||||
}
|
||||
};
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\ExaminationType;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
|
@ -26,6 +27,7 @@ class DatabaseSeeder extends Seeder
|
|||
DepartmentSeeder::class,
|
||||
EducationLevelSeeder::class,
|
||||
EducationFormSeeder::class,
|
||||
ExaminationTypeSeeder::class,
|
||||
DirectionSeeder::class,
|
||||
]);
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ExaminationTypeSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
DB::table('examination_types')->insert([
|
||||
[
|
||||
'name' => 'ЕГЭ',
|
||||
'description' => 'Unified State Examination',
|
||||
'position' => '1',
|
||||
'slug' => 'USE',
|
||||
],
|
||||
[
|
||||
'name' => 'СПО',
|
||||
'description' => 'secondary vocational education',
|
||||
'position' => '2',
|
||||
'slug' => 'SVE',
|
||||
],
|
||||
[
|
||||
'name' => 'магитсратура',
|
||||
'description' => 'type magistracy',
|
||||
'position' => '3',
|
||||
'slug' => 'MAG',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class=""> Создать тип экзамена</h1>
|
||||
{{ Form::open(['url' => route('examination_types.store'), 'method' => 'POST', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('name', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('description', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('slug', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('slug') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('position', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
@endauth
|
||||
@endsection
|
|
@ -0,0 +1,66 @@
|
|||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
|
||||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class="">Изменить тип экзамена</h1>
|
||||
{{ Form::open(['url' => route('examination_types.update', $examinationType), 'method' => 'PATCH', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('name', $examinationType->name, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('description', $examinationType->description, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('slug', $examinationType->slug, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('slug') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('position', $examinationType->position, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
@endauth
|
||||
@endsection
|
|
@ -0,0 +1,41 @@
|
|||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h2>Тип Экзамена</h2>
|
||||
<br>
|
||||
<a href="{{ route('examination_types.create') }}" class="btn btn-primary">Создать тип экзамена</a>
|
||||
<br>
|
||||
<br>
|
||||
<table class="table">
|
||||
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
|
||||
<tr>
|
||||
<th scope="col">Позиция</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Описание</th>
|
||||
<th scope="col">URL</th>
|
||||
<th scope="col">действия</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($types as $type)
|
||||
<tr class="">
|
||||
<td>{{ $type->position }}</td>
|
||||
<td><a href="{{ route('examination_types.show', $type) }}">{{ $type->name }}</a></td>
|
||||
<td>{{ Str::words($type->description, 10, '...') }}</td>
|
||||
<td>{{ $type->slug }}</td>
|
||||
<td>
|
||||
<a href="{{ route("examination_types.edit", $type) }}"
|
||||
class="btn btn-secondary">редактировать</a>
|
||||
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
|
||||
href="{{ route('examination_types.destroy', $type) }}"
|
||||
class="btn btn-danger">удалить</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<br>
|
||||
</div>
|
||||
@endsection
|
|
@ -0,0 +1,17 @@
|
|||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
@auth()
|
||||
<div class="container mt-4">
|
||||
<h2>Название</h2>
|
||||
<p>{{ $educationForm->name }}</p>
|
||||
<h2>Описание</h2>
|
||||
<p>{{ $educationForm->description }}</p>
|
||||
<h2>URL</h2>
|
||||
<p>{{ $educationForm->slug }}</p>
|
||||
<h2>Направления</h2>
|
||||
@foreach($directions as $direction)
|
||||
<p><a href="{{ route('directions.show', $direction) }}">{{ $direction->name }}</a></p>
|
||||
@endforeach
|
||||
</div>
|
||||
@endauth
|
||||
@endsection
|
|
@ -58,6 +58,7 @@
|
|||
<li class="list-group-item"><a href="{{ route('directions.index') }}">Направления</a></li>
|
||||
<li class="list-group-item"><a href="{{ route('education_levels.index') }}">Уровни образования</a></li>
|
||||
<li class="list-group-item"><a href="{{ route('education_forms.index') }}">Формы образования</a></li>
|
||||
<li class="list-group-item"><a href="{{ route('examination_types.index') }}">Тип Экзаменов</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
<main class="col-10">@yield('content')</main>
|
||||
|
|
|
@ -4,6 +4,7 @@ use App\Http\Controllers\admin\AdmissionController;
|
|||
use App\Http\Controllers\admin\Catalog\DepartmentController;
|
||||
use App\Http\Controllers\admin\Catalog\Direction\EducationFormController;
|
||||
use App\Http\Controllers\admin\Catalog\Direction\EducationLevelController;
|
||||
use App\Http\Controllers\admin\Catalog\Direction\ExaminationTypeController;
|
||||
use App\Http\Controllers\admin\Catalog\DirectionController;
|
||||
use App\Http\Controllers\admin\Catalog\EducationalInstitutionController;
|
||||
use App\Http\Controllers\admin\Catalog\FacultyController;
|
||||
|
@ -41,6 +42,9 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
|
|||
Route::resource('/education_forms', EducationFormController::class)
|
||||
->scoped(['education_form' => 'slug']);
|
||||
|
||||
Route::resource('/examination_types', ExaminationTypeController::class)
|
||||
->scoped(['examination_type' => 'slug']);
|
||||
|
||||
Route::resources([
|
||||
'/documents' => DocumentController::class,
|
||||
'/users' => UserController::class,
|
||||
|
|
Loading…
Reference in New Issue