add Education Level resource
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Failing after 1m51s Details
Tests & Lint & Deploy to Railway / deploy (push) Has been skipped Details

This commit is contained in:
aslan 2024-02-14 15:00:28 +03:00
parent 295d7a5711
commit 75899051c7
14 changed files with 388 additions and 0 deletions

View File

@ -0,0 +1,75 @@
<?php
namespace App\Http\Controllers\admin\Catalog;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\StoreEducationLevelRequest;
use App\Http\Requests\admin\Catalog\UpdateEducationLevelRequest;
use App\Models\EducationLevel;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
class EducationLevelController extends Controller
{
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$levels = EducationLevel::all();
return view('admin.catalog.education_level.index', compact('levels'));
}
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
return view('admin.catalog.education_level.create');
}
public function store(StoreEducationLevelRequest $request): RedirectResponse
{
$validated = $request->validated();
$level = new EducationLevel();
$level->name = $validated['name'];
$level->description = $validated['description'];
$level->slug = $validated['slug'];
$level->save();
return redirect()->route('education_levels.index');
}
public function show(
EducationLevel $educationLevel
): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$directions = $educationLevel->directions();
return view(
'admin.catalog.education_level.show',
compact('educationLevel', 'directions')
);
}
public function edit(EducationLevel $educationLevel)
{
return view('admin.catalog.education_level.edit', compact('educationLevel'));
}
public function update(UpdateEducationLevelRequest $request, EducationLevel $educationLevel): RedirectResponse
{
$validated = $request->validated();
$educationLevel->name = $validated['name'];
$educationLevel->description = $validated['description'];
$educationLevel->slug = $validated['slug'];
$educationLevel->save();
return redirect()->route('education_levels.index');
}
public function destroy(EducationLevel $educationLevel)
{
if($educationLevel->directions()->exists()) {
return back();
}
$educationLevel->delete();
return redirect()->route('education_levels.index');
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Http\Requests\admin\Catalog;
use Illuminate\Foundation\Http\FormRequest;
class StoreEducationLevelRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'name' => 'required|string|max:255|unique:education_levels,name',
'description' => 'string',
'slug' => 'required|string',
];
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Http\Requests\admin\Catalog;
use Illuminate\Foundation\Http\FormRequest;
class UpdateEducationLevelRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'name' => "required|string|max:255|unique:education_levels,name,{$this->education_level->id}",
'description' => 'string',
'slug' => 'required|string',
];
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class EducationLevel extends Model
{
use HasFactory;
protected $fillable = [
'id',
'name',
'description',
'slug',
];
public function directions(): HasMany
{
return $this->hasMany('App\Models\Direction', 'education_level_id');
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class EducationLevelFactory extends Factory
{
public function definition(): array
{
return [
'name' => fake()->name(),
'description' => fake()->text(),
'slug' => fake()->slug(),
];
}
}

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('education_levels', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('description');
$table->string('slug');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('education_levels');
}
};

View File

@ -24,6 +24,7 @@ class DatabaseSeeder extends Seeder
EducationalInstitutionSeeder::class,
FacultySeeder::class,
DepartmentSeeder::class,
EducationLevelSeeder::class,
DirectionSeeder::class,
]);

View File

@ -0,0 +1,31 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class EducationLevelSeeder extends Seeder
{
public function run(): void
{
DB::table('education_levels')->insert([
[
'name' => 'бакалавриат',
'description' => 'бакалавриат',
'slug' => 'baccalaureate',
],
[
'name' => 'специалитет',
'description' => 'специалитет',
'slug' => 'specialty',
],
[
'name' => 'магитсратура',
'description' => 'магитсратура',
'slug' => 'magistracy',
],
]);
}
}

View File

@ -0,0 +1,52 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Создать Уровень Образования</h1>
{{ Form::open(['url' => route('education_levels.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::submit('Создать', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,53 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class="">Езменить уровень образования</h1>
{{ Form::open(['url' => route('education_levels.update', $educationLevel), 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('name', 'Название') }}
</div>
<div class="mt-1">
{{ Form::text('name', $educationLevel->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', $educationLevel->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', $educationLevel->slug, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('slug') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,39 @@
@extends('layouts.admin_layout')
@section('content')
<div class="container">
<h2>Уровни образования</h2>
<br>
<a href="{{ route('education_levels.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">URL</th>
<th scope="col">действия</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach($levels as $level)
<tr class="">
<td><a href="{{ route('education_levels.show', $level) }}">{{ $level->name }}</a></td>
<td>{{ Str::words($level->description, 10, '...') }}</td>
<td>{{ $level->slug }}</td>
<td>
<a href="{{ route("education_levels.edit", $level) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('education_levels.destroy', $level) }}"
class="btn btn-danger">удалить</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<br>
<br>
</div>
@endsection

View File

@ -0,0 +1,17 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="container mt-4">
<h2>Название</h2>
<p>{{ $educationLevel->name }}</p>
<h2>Описание</h2>
<p>{{ $educationLevel->description }}</p>
<h2>URL</h2>
<p>{{ $educationLevel->slug }}</p>
<h2>Направления</h2>
@foreach($directions as $direction)
<p><a href="{{ route('directions.show', $direction) }}">{{ $direction->name }}</a></p>
@endforeach
</div>
@endauth
@endsection

View File

@ -56,6 +56,7 @@
<li class="list-group-item"><a href="{{ route('faculties.index') }}">Факультеты</a></li>
<li class="list-group-item"><a href="{{ route('departments.index') }}">Кафедры</a></li>
<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>
</ul>
</aside>
<main class="col-10">@yield('content')</main>

View File

@ -4,6 +4,7 @@ use App\Http\Controllers\admin\AdmissionController;
use App\Http\Controllers\admin\Catalog\DepartmentController;
use App\Http\Controllers\admin\Catalog\DirectionController;
use App\Http\Controllers\admin\Catalog\EducationalInstitutionController;
use App\Http\Controllers\admin\Catalog\EducationLevelController;
use App\Http\Controllers\admin\Catalog\FacultyController;
use App\Http\Controllers\admin\DocumentController;
use App\Http\Controllers\admin\UserController;
@ -33,6 +34,9 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
->scoped(['faculty' => 'slug']);
Route::resource('/admissions', AdmissionController::class);
Route::resource('/education_levels', EducationLevelController::class)
->scoped(['education_level' => 'slug']);
Route::resources([
'/documents' => DocumentController::class,
'/users' => UserController::class,