diff --git a/app/Http/Controllers/Catalog/EducationalInstitutionController.php b/app/Http/Controllers/admin/Catalog/EducationalInstitutionController.php similarity index 67% rename from app/Http/Controllers/Catalog/EducationalInstitutionController.php rename to app/Http/Controllers/admin/Catalog/EducationalInstitutionController.php index ebdb5fe..2a88084 100644 --- a/app/Http/Controllers/Catalog/EducationalInstitutionController.php +++ b/app/Http/Controllers/admin/Catalog/EducationalInstitutionController.php @@ -1,10 +1,10 @@ name = $validated['name']; $educationalInstitution->description = $validated['description']; + $educationalInstitution->slug = $validated['slug']; $educationalInstitution->position = $validated['position']; $educationalInstitution->save(); - return redirect()->route('educational-institutions.index'); + return redirect()->route('educational_institutions.index'); } public function show(EducationalInstitution $educationalInstitution) { - return view('catalog.educational-institution.show', compact('educationalInstitution')); + return view('admin.catalog.educational_institution.show', compact('educationalInstitution')); } public function edit(EducationalInstitution $educationalInstitution) { - return view('catalog.educational-institution.edit', compact('educationalInstitution')); + return view('admin.catalog.educational_institution.edit', compact('educationalInstitution')); } public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution) @@ -53,9 +54,10 @@ class EducationalInstitutionController extends Controller $educationalInstitution->name = $validated['name']; $educationalInstitution->description = $validated['description']; $educationalInstitution->position = $validated['position']; + $educationalInstitution->slug = $validated['slug']; $educationalInstitution->save(); - return redirect()->route('educational-institutions.index'); + return redirect()->route('educational_institutions.index'); } public function destroy(EducationalInstitution $educationalInstitution) @@ -65,6 +67,6 @@ class EducationalInstitutionController extends Controller } $educationalInstitution->delete(); - return redirect()->route('educational-institutions.index'); + return redirect()->route('educational_institutions.index'); } } diff --git a/app/Http/Requests/Catalog/StoreEducationalInstitutionRequest.php b/app/Http/Requests/admin/Catalog/StoreEducationalInstitutionRequest.php similarity index 59% rename from app/Http/Requests/Catalog/StoreEducationalInstitutionRequest.php rename to app/Http/Requests/admin/Catalog/StoreEducationalInstitutionRequest.php index ba95431..4ac4373 100644 --- a/app/Http/Requests/Catalog/StoreEducationalInstitutionRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreEducationalInstitutionRequest.php @@ -1,30 +1,23 @@ |string> - */ public function rules(): array { return [ 'position' => 'int|max:255', 'name' => 'required|string|max:255|unique:educational_institutions,name', 'description' => 'string', + 'slug' => 'required|string', ]; } } diff --git a/app/Http/Requests/Catalog/UpdateEducationalInstitutionRequest.php b/app/Http/Requests/admin/Catalog/UpdateEducationalInstitutionRequest.php similarity index 70% rename from app/Http/Requests/Catalog/UpdateEducationalInstitutionRequest.php rename to app/Http/Requests/admin/Catalog/UpdateEducationalInstitutionRequest.php index 1cd6d86..ac81bde 100644 --- a/app/Http/Requests/Catalog/UpdateEducationalInstitutionRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateEducationalInstitutionRequest.php @@ -1,30 +1,23 @@ - */ public function rules(): array { return [ 'position' => 'int|max:255', 'description' => 'string', + 'slug' => 'required|string', 'name' => [ 'required', 'string', diff --git a/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php b/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php index 4969eed..bb25df7 100644 --- a/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php @@ -15,10 +15,15 @@ class UpdateFacultyRequest extends FormRequest { return [ 'position' => 'int|max:255', - 'name' => 'required|string|max:255|unique:educational_institutions,name', 'description' => 'string', 'slug' => 'required|string', - 'educational_institution_id' => 'int' + 'educational_institution_id' => 'int', + 'name' => [ + 'required', + 'string', + 'max:255', + "unique:educational_institutions,name,{$this->faculty->id}", + ], ]; } } diff --git a/app/Policies/EducationalInstitutionPolicy.php b/app/Policies/EducationalInstitutionPolicy.php deleted file mode 100644 index 2bb3165..0000000 --- a/app/Policies/EducationalInstitutionPolicy.php +++ /dev/null @@ -1,66 +0,0 @@ - - */ class EducationalInstitutionFactory 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()->randomDigit(), ]; } } diff --git a/resources/views/admin/catalog/department/show.blade.php b/resources/views/admin/catalog/department/show.blade.php index 513e5dd..c6be54f 100644 --- a/resources/views/admin/catalog/department/show.blade.php +++ b/resources/views/admin/catalog/department/show.blade.php @@ -2,7 +2,7 @@ @section('content') @auth()
- + {{ $educationalInstitution->name }} -> {{ $faculty->name }} -> {{ $department->name }} diff --git a/resources/views/admin/catalog/direction/show.blade.php b/resources/views/admin/catalog/direction/show.blade.php index d3b6f8e..738f797 100644 --- a/resources/views/admin/catalog/direction/show.blade.php +++ b/resources/views/admin/catalog/direction/show.blade.php @@ -2,7 +2,7 @@ @section('content') @auth()
- + {{ $educationalInstitution->name }} -> diff --git a/resources/views/catalog/educational-institution/create.blade.php b/resources/views/admin/catalog/educational_institution/create.blade.php similarity index 79% rename from resources/views/catalog/educational-institution/create.blade.php rename to resources/views/admin/catalog/educational_institution/create.blade.php index 293d49c..dc6fd9c 100644 --- a/resources/views/catalog/educational-institution/create.blade.php +++ b/resources/views/admin/catalog/educational_institution/create.blade.php @@ -1,11 +1,10 @@ @extends('layouts.admin-layout') @section('content') - @auth()

Создать учебное заведение

- {{ Form::open(['url' => route('educational-institutions.store'), 'method' => 'POST', 'class' => '']) }} + {{ Form::open(['url' => route('educational_institutions.store'), 'method' => 'POST', 'class' => '']) }}
{{ Form::label('position', 'Позиция') }} @@ -42,6 +41,17 @@ {{ $errors->first('description') }} @endif
+
+ {{ Form::label('slug', 'URL') }} +
+
+ {{ Form::text('slug', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('slug') }} + @endif +
{{ Form::submit('создать', ['class' => 'btn btn-primary']) }}
diff --git a/resources/views/catalog/educational-institution/edit.blade.php b/resources/views/admin/catalog/educational_institution/edit.blade.php similarity index 79% rename from resources/views/catalog/educational-institution/edit.blade.php rename to resources/views/admin/catalog/educational_institution/edit.blade.php index 5e85ac4..9ce40b4 100644 --- a/resources/views/catalog/educational-institution/edit.blade.php +++ b/resources/views/admin/catalog/educational_institution/edit.blade.php @@ -1,11 +1,10 @@ @extends('layouts.admin-layout') @section('content') - @auth()

Изменить учебное заведение

- {{ Form::model($educationalInstitution, ['route' => ['educational-institutions.update', $educationalInstitution], 'method' => 'PATCH', 'class' => '']) }} + {{ Form::model($educationalInstitution, ['route' => ['educational_institutions.update', $educationalInstitution], 'method' => 'PATCH', 'class' => '']) }}
{{ Form::label('position', 'Позиция') }} @@ -42,6 +41,17 @@ {{ $errors->first('description') }} @endif
+
+ {{ Form::label('slug', 'URL') }} +
+
+ {{ Form::text('slug', $educationalInstitution->slug, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('slug') }} + @endif +
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
diff --git a/resources/views/catalog/educational-institution/index.blade.php b/resources/views/admin/catalog/educational_institution/index.blade.php similarity index 75% rename from resources/views/catalog/educational-institution/index.blade.php rename to resources/views/admin/catalog/educational_institution/index.blade.php index 8906b4e..f433d28 100644 --- a/resources/views/catalog/educational-institution/index.blade.php +++ b/resources/views/admin/catalog/educational_institution/index.blade.php @@ -3,16 +3,16 @@

Учебные заведения


- Создать учебное заведение + Создать учебное заведение

- + @@ -21,12 +21,15 @@ @foreach($educationalInstitutions as $educationalInstitution) - + - + + @@ -24,6 +25,7 @@ +
Позиция Название ОписаниеURL действия
{{ $educationalInstitution->position }}{{ $educationalInstitution->name }} + {{ $educationalInstitution->name }} + {{ Str::words($educationalInstitution->description, 10, '...') }}редактировать + {{ $educationalInstitution->slug }}редактировать удалить @@ -38,5 +41,4 @@

- @endsection diff --git a/resources/views/catalog/educational-institution/show.blade.php b/resources/views/admin/catalog/educational_institution/show.blade.php similarity index 89% rename from resources/views/catalog/educational-institution/show.blade.php rename to resources/views/admin/catalog/educational_institution/show.blade.php index faca316..93351eb 100644 --- a/resources/views/catalog/educational-institution/show.blade.php +++ b/resources/views/admin/catalog/educational_institution/show.blade.php @@ -1,6 +1,5 @@ @extends('layouts.admin-layout') @section('content') - @auth()

Название

@@ -9,6 +8,8 @@

{{ $educationalInstitution->description }}

Позиция

{{ $educationalInstitution->position }}

+

URL

+

{{ $educationalInstitution->slug }}

Факультеты

@foreach($educationalInstitution->faculties as $faculty)

{{ $faculty->name }}

diff --git a/resources/views/catalog/faculty/index.blade.php b/resources/views/admin/catalog/faculty/index.blade.php similarity index 94% rename from resources/views/catalog/faculty/index.blade.php rename to resources/views/admin/catalog/faculty/index.blade.php index 9bf0f19..7614951 100644 --- a/resources/views/catalog/faculty/index.blade.php +++ b/resources/views/admin/catalog/faculty/index.blade.php @@ -13,6 +13,7 @@
Позиция Название ОписаниеURL Учебное заведение действия {{ $faculty->position }} {{ $faculty->name }} {{ Str::words($faculty->description, 10, '...') }}{{ Str::words($faculty->slug, 10, '...') }} {{ $faculty->educationalInstitution->name }} редактировать diff --git a/resources/views/catalog/faculty/show.blade.php b/resources/views/admin/catalog/faculty/show.blade.php similarity index 84% rename from resources/views/catalog/faculty/show.blade.php rename to resources/views/admin/catalog/faculty/show.blade.php index c83903a..e79290c 100644 --- a/resources/views/catalog/faculty/show.blade.php +++ b/resources/views/admin/catalog/faculty/show.blade.php @@ -1,8 +1,7 @@ @extends('layouts.admin-layout') @section('content') - @auth() -
{{ $faculty->educationalInstitution->name }} -> {{ $faculty->name }}
+
{{ $faculty->educationalInstitution->name }} -> {{ $faculty->name }}

Название

{{ $faculty->name }}

@@ -10,6 +9,8 @@

{{ $faculty->description }}

Позиция

{{ $faculty->position }}

+

URL

+

{{ $faculty->slug }}

Кафедры

@foreach($faculty->departments as $department)

{{ $department->name }}

diff --git a/tests/Feature/admin/catalog/EducationalInstitutionTest.php b/tests/Feature/admin/catalog/EducationalInstitutionTest.php new file mode 100644 index 0000000..163ac3e --- /dev/null +++ b/tests/Feature/admin/catalog/EducationalInstitutionTest.php @@ -0,0 +1,106 @@ +educationalInstitution = EducationalInstitution::factory()->create(); + $this->data = EducationalInstitution::factory()->make()->only([ + 'position', + 'name', + 'description', + 'slug', + ]); + + $this->faculty = Faculty::factory()->create(); + + $this->user = User::factory()->create([ + 'name' => 'admin', + 'email' => 'test@example.com', + 'password' => 123456 + ]); + } + + public function testIndexEducationalInstitutionsPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('educational_institutions.index')); + + $response->assertOk(); + } + + public function testCreateEducationalInstitutionPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('educational_institutions.create')); + + $response->assertOk(); + } + + public function testStoreEducationalInstitution(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->post(route('educational_institutions.store', $this->data)); + + $response->assertRedirect(route('educational_institutions.index')); + + $this->assertDatabaseHas('educational_institutions', $this->data); + } + + public function testShowEducationalInstitutionPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('educational_institutions.show', $this->educationalInstitution)); + + $response->assertOk(); + } + + public function testEditEducationalInstitutionPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('educational_institutions.edit', $this->educationalInstitution)); + + $response->assertOk(); + } + + public function testUpdateEducationalInstitution(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->patch(route('educational_institutions.update', $this->educationalInstitution), $this->data); + + $response->assertRedirect(route('educational_institutions.index')); + + $this->assertDatabaseHas('educational_institutions', $this->data); + } + + public function testDestroyFaculty(): void + { + $this->faculty->delete(); + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->delete(route('educational_institutions.destroy', $this->educationalInstitution)); + + $response->assertRedirect(route('educational_institutions.index')); + + $this->assertDatabaseMissing('educational_institutions', $this->educationalInstitution->toArray()); + } +} diff --git a/tests/Feature/admin/catalog/FacultyTest.php b/tests/Feature/admin/catalog/FacultyTest.php index 418e8e9..0c1efc4 100644 --- a/tests/Feature/admin/catalog/FacultyTest.php +++ b/tests/Feature/admin/catalog/FacultyTest.php @@ -3,7 +3,6 @@ namespace Tests\Feature\admin\catalog; use App\Models\Department; -use App\Models\Direction; use App\Models\EducationalInstitution; use App\Models\Faculty; use App\Models\User; @@ -13,6 +12,7 @@ class FacultyTest extends TestCase { private User $user; private Faculty $faculty; + private Department $department; private array $data; protected function setUp(): void { @@ -37,7 +37,7 @@ class FacultyTest extends TestCase ]); } - public function testIndexFacultysPage(): void + public function testIndexFacultiesPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false])