diff --git a/app/Http/Controllers/Catalog/DirectionController.php b/app/Http/Controllers/Catalog/DirectionController.php new file mode 100644 index 0000000..2df2941 --- /dev/null +++ b/app/Http/Controllers/Catalog/DirectionController.php @@ -0,0 +1,78 @@ +validated(); + + $direction = new Direction(); + $direction->name = $validated['name']; + $direction->description = $validated['description']; + $direction->position = $validated['position']; + $direction->slug = $validated['slug']; + $direction->department_id = $validated['department_id']; + $direction->save(); + + return redirect()->route('directions.index'); + } + + public function show(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application + { + return view('catalog.direction.show', compact('direction')); + } + + public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application + { + $departments = Department::pluck('name', 'id'); + return view('catalog.direction.edit', compact('direction', 'departments')); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateDepartmentRequest $request, Direction $direction) + { + $validated = $request->validated(); + + $direction->name = $validated['name']; + $direction->description = $validated['description']; + $direction->position = $validated['position']; + $direction->department_id = $validated['department_id']; + $direction->save(); + + return redirect()->route('directions.index'); + } + + public function destroy(Direction $direction): RedirectResponse + { + $direction->delete(); + return redirect()->route('directions.index'); + } +} diff --git a/app/Http/Requests/StoreDirectionRequest.php b/app/Http/Requests/StoreDirectionRequest.php new file mode 100644 index 0000000..c51398b --- /dev/null +++ b/app/Http/Requests/StoreDirectionRequest.php @@ -0,0 +1,32 @@ +|string> + */ + public function rules(): array + { + return [ + 'position' => 'required|int|max:255', + 'name' => 'required|string|max:255|unique:educational_institutions,name', + 'description' => 'string', + 'slug' => 'required|string', + 'department_id' => 'required|int' + ]; + } +} diff --git a/app/Http/Requests/UpdateDirectionRequest.php b/app/Http/Requests/UpdateDirectionRequest.php new file mode 100644 index 0000000..7c8e7cd --- /dev/null +++ b/app/Http/Requests/UpdateDirectionRequest.php @@ -0,0 +1,37 @@ + + */ + public function rules(): array + { + return [ + 'position' => 'int|max:255', + 'description' => 'string', + 'department_id' => 'int|required', + 'name' => [ + 'required', + 'string', + 'max:255', + "unique:educational_institutions,name,{$this->direction->id}", + ], + ]; + } +} diff --git a/app/Models/Direction.php b/app/Models/Direction.php new file mode 100644 index 0000000..98f8ce7 --- /dev/null +++ b/app/Models/Direction.php @@ -0,0 +1,24 @@ +belongsTo(Department::class); + } +} diff --git a/app/Policies/DirectionPolicy.php b/app/Policies/DirectionPolicy.php new file mode 100644 index 0000000..885ae5c --- /dev/null +++ b/app/Policies/DirectionPolicy.php @@ -0,0 +1,66 @@ + + */ +class DirectionFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2024_02_09_114155_create_directions_table.php b/database/migrations/2024_02_09_114155_create_directions_table.php new file mode 100644 index 0000000..7ba432a --- /dev/null +++ b/database/migrations/2024_02_09_114155_create_directions_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name'); + $table->text('description'); + $table->integer('position'); + $table->string('slug'); + $table->foreignId('department_id')->constrained('departments'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('directions'); + } +}; diff --git a/database/seeders/DirectionSeeder.php b/database/seeders/DirectionSeeder.php new file mode 100644 index 0000000..b6bbc3b --- /dev/null +++ b/database/seeders/DirectionSeeder.php @@ -0,0 +1,17 @@ + +
+

Создать Направление

+ {{ Form::open(['url' => route('directions.store'), 'method' => 'POST', 'class' => '']) }} +
+
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('name', 'Название') }} +
+
+ {{ Form::text('name', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+
+ {{ Form::label('department_id', 'Кафедры') }} +
+
+ {{ Form::select('department_id', $departments, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('department_id') }} + @endif +
+
+ {{ Form::label('slug', 'URL') }} +
+
+ {{ Form::text('slug', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('slug') }} + @endif +
+
+ {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+ + @endauth +@endsection diff --git a/resources/views/catalog/direction/edit.blade.php b/resources/views/catalog/direction/edit.blade.php new file mode 100644 index 0000000..5193984 --- /dev/null +++ b/resources/views/catalog/direction/edit.blade.php @@ -0,0 +1,64 @@ +@extends('layouts.admin-layout') +@section('content') + + @auth() +
+
+

Создать кафедру

+ {{ Form::open(['url' => route('departments.update', $direction), 'method' => 'PATCH', 'class' => '']) }} +
+
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', $direction->position, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('name', 'Название') }} +
+
+ {{ Form::text('name', $direction->name, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', $direction->description, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+
+ {{ Form::label('educational_institution_id', 'Факультет') }} +
+
+ {{ Form::select('faculty_id', $departments, $direction->department->id, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('educational_institution_id') }} + @endif +
+
+ {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/catalog/direction/index.blade.php b/resources/views/catalog/direction/index.blade.php new file mode 100644 index 0000000..c1adf31 --- /dev/null +++ b/resources/views/catalog/direction/index.blade.php @@ -0,0 +1,43 @@ +@extends('layouts.admin-layout') +@section('content') +
+

Направления

+
+ Создать Направление +
+
+ + + + + + + + + + + + + + @foreach($directions as $direction) + + + + + + + + @endforeach + +
ПозицияНазваниеОписаниеКафедрадействия
{{ $direction->position }}{{ $direction->name }}{{ Str::words($direction->description, 10, '...') }}{{ $direction->department->name }} + редактировать + удалить +
+
+
+
+ +@endsection diff --git a/resources/views/catalog/direction/show.blade.php b/resources/views/catalog/direction/show.blade.php new file mode 100644 index 0000000..1736ceb --- /dev/null +++ b/resources/views/catalog/direction/show.blade.php @@ -0,0 +1,36 @@ +@php + use App\Models\Direction; + use App\Models\Department; + use App\Models\EducationalInstitution;use App\Models\Faculty;use Illuminate\Support\Collection; + /** @var Collection|Direction[] $direction */ + + $department = Department::find($direction->department->id); + $faculty = Faculty::find($department->faculty->id); + $educationalInstitution = EducationalInstitution::find($faculty->educationalInstitution->id); +@endphp +@extends('layouts.admin-layout') +@section('content') + @auth() +
+ + {{ $educationalInstitution->name }} + + -> + {{ $faculty->name }} + -> + {{ $department->name }} + -> {{ $direction->name }} + +
+
+

Название

+

{{ $direction->name }}

+

Описание

+

{{ $direction->description }}

+

Позиция

+

{{ $direction->position }}

+

Кафедра

+

{{ $department->name }}

+
+ @endauth +@endsection diff --git a/resources/views/layouts/admin-layout.blade.php b/resources/views/layouts/admin-layout.blade.php index 2621ac3..2be4020 100644 --- a/resources/views/layouts/admin-layout.blade.php +++ b/resources/views/layouts/admin-layout.blade.php @@ -62,6 +62,7 @@ заведения
  • Факультеты
  • Кафедры
  • +
  • Направления
  • @yield('content')
    diff --git a/routes/admin.php b/routes/admin.php index c8cdeab..70bdf4a 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -1,6 +1,7 @@ prefix('admin')->group(function () { Route::resource('/educational-institutions', EducationalInstitutionController::class) ->scoped(['educational_institution' => 'slug']); + Route::resource('/directions', DirectionController::class) + ->scoped(['educational_institution' => 'slug']); + Route::resources([ '/files' => DocumentController::class, '/users' => UserController::class,