diff --git a/app/Http/Controllers/Catalog/DepartmentController.php b/app/Http/Controllers/admin/Catalog/DepartmentController.php similarity index 76% rename from app/Http/Controllers/Catalog/DepartmentController.php rename to app/Http/Controllers/admin/Catalog/DepartmentController.php index c50c8bb..529c855 100644 --- a/app/Http/Controllers/Catalog/DepartmentController.php +++ b/app/Http/Controllers/admin/Catalog/DepartmentController.php @@ -1,10 +1,10 @@ faculty->id); + $educationalInstitution = $faculty->educationalInstitution; + return view('admin.catalog.department.show', compact('department', 'faculty', 'educationalInstitution')); } public function edit(Department $department): View|Application|Factory|\Illuminate\Contracts\Foundation\Application { $faculties = Faculty::pluck('name', 'id'); - return view('catalog.department.edit', compact('department', 'faculties')); + return view('admin.catalog.department.edit', compact('department', 'faculties')); } public function update(UpdateDepartmentRequest $request, Department $department): RedirectResponse diff --git a/app/Http/Requests/Catalog/StoreDepartmentRequest.php b/app/Http/Requests/admin/Catalog/StoreDepartmentRequest.php similarity index 84% rename from app/Http/Requests/Catalog/StoreDepartmentRequest.php rename to app/Http/Requests/admin/Catalog/StoreDepartmentRequest.php index c255d54..2383243 100644 --- a/app/Http/Requests/Catalog/StoreDepartmentRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreDepartmentRequest.php @@ -1,6 +1,6 @@ 'required|int|max:255', 'name' => 'required|string|max:255|unique:educational_institutions,name', 'description' => 'string', - 'faculty_id' => 'required|int' + 'slug' => 'required|string', + 'faculty_id' => 'required|int', ]; } } diff --git a/app/Http/Requests/Catalog/UpdateDepartmentRequest.php b/app/Http/Requests/admin/Catalog/UpdateDepartmentRequest.php similarity index 65% rename from app/Http/Requests/Catalog/UpdateDepartmentRequest.php rename to app/Http/Requests/admin/Catalog/UpdateDepartmentRequest.php index 253059a..df0e43c 100644 --- a/app/Http/Requests/Catalog/UpdateDepartmentRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateDepartmentRequest.php @@ -1,30 +1,22 @@ |string> - */ public function rules(): array { return [ - 'position' => 'int|max:255', + 'position' => 'required|int|max:255', 'description' => 'string', + 'slug' => 'string|required', 'faculty_id' => 'int|required', 'name' => [ 'required', diff --git a/app/Models/Department.php b/app/Models/Department.php index 2e32ed4..91517cb 100644 --- a/app/Models/Department.php +++ b/app/Models/Department.php @@ -14,6 +14,7 @@ class Department extends Model protected $fillable = [ 'id', 'name', + 'slug', 'description', 'position', ]; diff --git a/app/Policies/DepartmentPolicy.php b/app/Policies/DepartmentPolicy.php deleted file mode 100644 index e60adbd..0000000 --- a/app/Policies/DepartmentPolicy.php +++ /dev/null @@ -1,66 +0,0 @@ - - */ class DepartmentFactory extends Factory { - /** - * Define the model's default state. - * - * @return array - */ public function definition(): array { return [ - // + 'name' => fake()->name(), + 'description' => fake()->text(), + 'slug' => fake()->slug(), + 'position' => fake()->randomNumber(), + 'faculty_id' => fake()->realTextBetween(1,5,1), ]; } } diff --git a/database/migrations/2024_02_08_074258_create_departments_table.php b/database/migrations/2024_02_08_074258_create_departments_table.php index ab751c8..1850030 100644 --- a/database/migrations/2024_02_08_074258_create_departments_table.php +++ b/database/migrations/2024_02_08_074258_create_departments_table.php @@ -14,8 +14,9 @@ return new class extends Migration Schema::create('departments', function (Blueprint $table) { $table->id(); $table->string('name'); - $table->string('description'); + $table->text('description'); $table->integer('position'); + $table->string('slug'); $table->foreignId('faculty_id')->constrained('faculties'); $table->timestamps(); }); diff --git a/database/seeders/DepartmentSeeder.php b/database/seeders/DepartmentSeeder.php index ce35944..281fa0b 100644 --- a/database/seeders/DepartmentSeeder.php +++ b/database/seeders/DepartmentSeeder.php @@ -20,12 +20,14 @@ class DepartmentSeeder extends Seeder 'name' => 'Кафедра инф. без.', 'description' => 'Кафедра инф. без. описание', 'position' => 1, + 'slug' => 'departmentInfWithout', 'faculty_id' => 1, ], [ 'name' => 'кафедра стоматологии', 'description' => 'кафедра стоматологии описание', 'position' => 2, + 'slug' => 'departmentOfDentistry', 'faculty_id' => 2, ], ]); diff --git a/resources/views/catalog/department/edit.blade.php b/resources/views/admin/catalog/department/edit.blade.php similarity index 100% rename from resources/views/catalog/department/edit.blade.php rename to resources/views/admin/catalog/department/edit.blade.php diff --git a/resources/views/catalog/department/index.blade.php b/resources/views/admin/catalog/department/index.blade.php similarity index 95% rename from resources/views/catalog/department/index.blade.php rename to resources/views/admin/catalog/department/index.blade.php index b97cf3d..8d1d651 100644 --- a/resources/views/catalog/department/index.blade.php +++ b/resources/views/admin/catalog/department/index.blade.php @@ -13,6 +13,7 @@ Позиция Название Описание + URL Факультет действия @@ -24,6 +25,7 @@ {{ $department->position }} {{ $department->name }} {{ Str::words($department->description, 10, '...') }} + {{ $department->slug }} {{ $department->faculty->name }} faculty->id) -@endphp @extends('layouts.admin-layout') @section('content') @auth()
- - {{ $faculty->educationalInstitution->name }} + + {{ $educationalInstitution->name }} -> {{ $faculty->name }} -> {{ $department->name }}
@@ -22,10 +14,10 @@

{{ $department->description }}

Позиция

{{ $department->position }}

- {{--

Факультеты

--}} - {{-- @foreach($department->faculties as $faculty)--}} - {{--

{{ $faculty->name }}

--}} - {{-- @endforeach--}} +

Направления подготовки

+ @foreach($department->directions as $direction) +

{{ $direction->name }}

+ @endforeach @endauth @endsection diff --git a/routes/admin.php b/routes/admin.php index 70bdf4a..c4071b6 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -1,31 +1,33 @@ prefix('admin')->group(function () { Route::get('/dashboard', function () { return view('admin'); })->name('dashboard'); - Route::get('/files/create/{document?}', [DocumentController::class, 'create'])->name('document_create'); - Route::get('/files/download/{Document}', [DocumentController::class, 'download'])->name('document.download'); + Route::get('/documents/create/{document?}', [DocumentController::class, 'create'])->name('documents_create'); + Route::get('/documents/download/{Document}', [DocumentController::class, 'download'])->name('documents_download'); Route::resource('/educational-institutions', EducationalInstitutionController::class) ->scoped(['educational_institution' => 'slug']); Route::resource('/directions', DirectionController::class) - ->scoped(['educational_institution' => 'slug']); + ->scoped(['directions' => 'slug']); + + Route::resource('/departments', DepartmentController::class) + ->scoped(['department' => 'slug']); Route::resources([ - '/files' => DocumentController::class, + '/documents' => DocumentController::class, '/users' => UserController::class, '/admin-reception-screen' => ReceptionScreenController::class, '/faculties' => FacultyController::class, - '/departments' => DepartmentController::class, ]); });