forked from aslan/applicant-site
prodV1 #2
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Catalog;
|
||||
namespace App\Http\Controllers\admin\Catalog;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreEducationalInstitutionRequest;
|
||||
use App\Http\Requests\UpdateEducationalInstitutionRequest;
|
||||
use App\Http\Requests\admin\Catalog\StoreEducationalInstitutionRequest;
|
||||
use App\Http\Requests\admin\Catalog\UpdateEducationalInstitutionRequest;
|
||||
use App\Models\EducationalInstitution;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
@ -15,12 +15,12 @@ class EducationalInstitutionController extends Controller
|
|||
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$educationalInstitutions = EducationalInstitution::all();
|
||||
return view('catalog.educational-institution.index', compact('educationalInstitutions'));
|
||||
return view('admin.catalog.educational_institution.index', compact('educationalInstitutions'));
|
||||
}
|
||||
|
||||
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
return view('catalog.educational-institution.create');
|
||||
return view('admin.catalog.educational_institution.create');
|
||||
}
|
||||
|
||||
public function store(StoreEducationalInstitutionRequest $request)
|
||||
|
@ -30,20 +30,21 @@ class EducationalInstitutionController extends Controller
|
|||
$educationalInstitution = new EducationalInstitution();
|
||||
$educationalInstitution->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');
|
||||
}
|
||||
}
|
|
@ -1,30 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Catalog;
|
||||
namespace App\Http\Requests\admin\Catalog;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreEducationalInstitutionRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'position' => 'int|max:255',
|
||||
'name' => 'required|string|max:255|unique:educational_institutions,name',
|
||||
'description' => 'string',
|
||||
'slug' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -1,30 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Catalog;
|
||||
namespace App\Http\Requests\admin\Catalog;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateEducationalInstitutionRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'position' => 'int|max:255',
|
||||
'description' => 'string',
|
||||
'slug' => 'required|string',
|
||||
'name' => [
|
||||
'required',
|
||||
'string',
|
|
@ -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}",
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\EducationalInstitution;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class EducationalInstitutionPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, EducationalInstitution $educationalInstitution): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, EducationalInstitution $educationalInstitution): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, EducationalInstitution $educationalInstitution): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, EducationalInstitution $educationalInstitution): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, EducationalInstitution $educationalInstitution): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -4,20 +4,15 @@ namespace Database\Factories;
|
|||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\EducationalInstitution>
|
||||
*/
|
||||
class EducationalInstitutionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
'name' => fake()->name(),
|
||||
'description' => fake()->text(),
|
||||
'slug' => fake()->slug(),
|
||||
'position' => fake()->randomDigit(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
@section('content')
|
||||
@auth()
|
||||
<h6>
|
||||
<a href="{{ route('educational-institutions.show', $educationalInstitution) }}">
|
||||
<a href="{{ route('educational_institutions.show', $educationalInstitution) }}">
|
||||
{{ $educationalInstitution->name }}
|
||||
</a>-> <a href="{{ route('faculties.show', $faculty) }}">{{ $faculty->name }}</a>
|
||||
-> {{ $department->name }}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
@section('content')
|
||||
@auth()
|
||||
<h6>
|
||||
<a href="{{ route('educational-institutions.show', $educationalInstitution) }}">
|
||||
<a href="{{ route('educational_institutions.show', $educationalInstitution) }}">
|
||||
{{ $educationalInstitution->name }}
|
||||
</a>
|
||||
->
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
@extends('layouts.admin-layout')
|
||||
@section('content')
|
||||
|
||||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class=""> Создать учебное заведение</h1>
|
||||
{{ Form::open(['url' => route('educational-institutions.store'), 'method' => 'POST', 'class' => '']) }}
|
||||
{{ Form::open(['url' => route('educational_institutions.store'), 'method' => 'POST', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div>
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
|
@ -42,6 +41,17 @@
|
|||
{{ $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-4">
|
||||
{{ Form::submit('создать', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
|
@ -1,11 +1,10 @@
|
|||
@extends('layouts.admin-layout')
|
||||
@section('content')
|
||||
|
||||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class="">Изменить учебное заведение</h1>
|
||||
{{ Form::model($educationalInstitution, ['route' => ['educational-institutions.update', $educationalInstitution], 'method' => 'PATCH', 'class' => '']) }}
|
||||
{{ Form::model($educationalInstitution, ['route' => ['educational_institutions.update', $educationalInstitution], 'method' => 'PATCH', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div>
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
|
@ -42,6 +41,17 @@
|
|||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('slug', $educationalInstitution->slug, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('slug') }}
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
|
@ -3,16 +3,16 @@
|
|||
<div class="container">
|
||||
<h2>Учебные заведения</h2>
|
||||
<br>
|
||||
<a href="{{ route('educational-institutions.create') }}" class="btn btn-primary">Создать учебное заведение</a>
|
||||
<a href="{{ route('educational_institutions.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>
|
||||
|
@ -21,12 +21,15 @@
|
|||
@foreach($educationalInstitutions as $educationalInstitution)
|
||||
<tr class="">
|
||||
<th scope="row">{{ $educationalInstitution->position }}</th>
|
||||
<td><a href="{{ route('educational-institutions.show', $educationalInstitution) }}">{{ $educationalInstitution->name }}</a></td>
|
||||
<td>
|
||||
<a href="{{ route('educational_institutions.show', $educationalInstitution) }}">{{ $educationalInstitution->name }}</a>
|
||||
</td>
|
||||
<td>{{ Str::words($educationalInstitution->description, 10, '...') }}</td>
|
||||
<td class="col-3"><a href="{{ route("educational-institutions.edit", $educationalInstitution) }}"
|
||||
class="btn btn-secondary">редактировать</a>
|
||||
<th scope="row">{{ $educationalInstitution->slug }}</th>
|
||||
<td class="col-3"><a href="{{ route("educational_institutions.edit", $educationalInstitution) }}"
|
||||
class="btn btn-secondary">редактировать</a>
|
||||
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
|
||||
href="{{ route('educational-institutions.destroy', $educationalInstitution) }}"
|
||||
href="{{ route('educational_institutions.destroy', $educationalInstitution) }}"
|
||||
class="btn btn-danger">
|
||||
удалить
|
||||
</a>
|
||||
|
@ -38,5 +41,4 @@
|
|||
<br>
|
||||
<br>
|
||||
</div>
|
||||
|
||||
@endsection
|
|
@ -1,6 +1,5 @@
|
|||
@extends('layouts.admin-layout')
|
||||
@section('content')
|
||||
|
||||
@auth()
|
||||
<div class="container mt-4">
|
||||
<h2>Название</h2>
|
||||
|
@ -9,6 +8,8 @@
|
|||
<p>{{ $educationalInstitution->description }}</p>
|
||||
<h2>Позиция</h2>
|
||||
<p>{{ $educationalInstitution->position }}</p>
|
||||
<h2>URL</h2>
|
||||
<p>{{ $educationalInstitution->slug }}</p>
|
||||
<h2>Факультеты</h2>
|
||||
@foreach($educationalInstitution->faculties as $faculty)
|
||||
<p><a href="{{ route('faculties.show', $faculty) }}">{{ $faculty->name }}</a></p>
|
|
@ -13,6 +13,7 @@
|
|||
<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>
|
||||
<th scope="col"></th>
|
||||
|
@ -24,6 +25,7 @@
|
|||
<th scope="row">{{ $faculty->position }}</th>
|
||||
<td><a href="{{ route('faculties.show', $faculty) }}">{{ $faculty->name }}</a></td>
|
||||
<td>{{ Str::words($faculty->description, 10, '...') }}</td>
|
||||
<td>{{ Str::words($faculty->slug, 10, '...') }}</td>
|
||||
<td>{{ $faculty->educationalInstitution->name }}</td>
|
||||
<td><a href="{{ route("faculties.edit", $faculty) }}"
|
||||
class="btn btn-secondary">редактировать</a>
|
|
@ -1,8 +1,7 @@
|
|||
@extends('layouts.admin-layout')
|
||||
@section('content')
|
||||
|
||||
@auth()
|
||||
<h6><a href="{{ route('educational-institutions.show', $faculty->educationalInstitution) }}">{{ $faculty->educationalInstitution->name }}</a> -> {{ $faculty->name }}</h6>
|
||||
<h6><a href="{{ route('educational_institutions.show', $faculty->educationalInstitution) }}">{{ $faculty->educationalInstitution->name }}</a> -> {{ $faculty->name }}</h6>
|
||||
<div class="container mt-4">
|
||||
<h2>Название</h2>
|
||||
<p>{{ $faculty->name }}</p>
|
||||
|
@ -10,6 +9,8 @@
|
|||
<p>{{ $faculty->description }}</p>
|
||||
<h2>Позиция</h2>
|
||||
<p>{{ $faculty->position }}</p>
|
||||
<h2>URL</h2>
|
||||
<p>{{ $faculty->slug }}</p>
|
||||
<h2>Кафедры</h2>
|
||||
@foreach($faculty->departments as $department)
|
||||
<p><a href="{{ route('departments.show', $department) }}">{{ $department->name }}</a></p>
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\admin\catalog;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\EducationalInstitution;
|
||||
use App\Models\Faculty;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EducationalInstitutionTest extends TestCase
|
||||
{
|
||||
private User $user;
|
||||
private EducationalInstitution $educationalInstitution;
|
||||
private Faculty $faculty;
|
||||
private array $data;
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->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());
|
||||
}
|
||||
}
|
|
@ -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])
|
||||
|
|
Loading…
Reference in New Issue