forked from aslan/applicant-site
prodV1 #2
|
@ -1,11 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Catalog;
|
namespace App\Http\Controllers\admin\Catalog;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\StoreFacultyRequest;
|
use App\Http\Requests\admin\Catalog\StoreFacultyRequest;
|
||||||
use App\Http\Requests\UpdateFacultyRequest;
|
use App\Http\Requests\admin\Catalog\UpdateFacultyRequest;
|
||||||
use App\Models\Department;
|
|
||||||
use App\Models\EducationalInstitution;
|
use App\Models\EducationalInstitution;
|
||||||
use App\Models\Faculty;
|
use App\Models\Faculty;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
@ -18,13 +17,13 @@ class FacultyController extends Controller
|
||||||
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
$faculties = Faculty::all();
|
$faculties = Faculty::all();
|
||||||
return view('catalog.faculty.index', compact('faculties'));
|
return view('admin.catalog.faculty.index', compact('faculties'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
$educationalInstitutions = EducationalInstitution::pluck('name', 'id');
|
$educationalInstitutions = EducationalInstitution::pluck('name', 'id');
|
||||||
return view('catalog.faculty.create', compact('educationalInstitutions'));
|
return view('admin.catalog.faculty.create', compact('educationalInstitutions'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(StoreFacultyRequest $request): RedirectResponse
|
public function store(StoreFacultyRequest $request): RedirectResponse
|
||||||
|
@ -35,6 +34,7 @@ class FacultyController extends Controller
|
||||||
$faculty->name = $validated['name'];
|
$faculty->name = $validated['name'];
|
||||||
$faculty->description = $validated['description'];
|
$faculty->description = $validated['description'];
|
||||||
$faculty->position = $validated['position'];
|
$faculty->position = $validated['position'];
|
||||||
|
$faculty->slug = $validated['slug'];
|
||||||
$faculty->educational_institution_id = $validated['educational_institution_id'];
|
$faculty->educational_institution_id = $validated['educational_institution_id'];
|
||||||
$faculty->save();
|
$faculty->save();
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@ class FacultyController extends Controller
|
||||||
|
|
||||||
public function show(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function show(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
return view('catalog.faculty.show', compact('faculty'));
|
return view('admin.catalog.faculty.show', compact('faculty'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function edit(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
$educationalInstitutions = EducationalInstitution::pluck('name', 'id');
|
$educationalInstitutions = EducationalInstitution::pluck('name', 'id');
|
||||||
return view('catalog.faculty.edit', compact('faculty', 'educationalInstitutions'));
|
return view('admin.catalog.faculty.edit', compact('faculty', 'educationalInstitutions'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(UpdateFacultyRequest $request, Faculty $faculty): RedirectResponse
|
public function update(UpdateFacultyRequest $request, Faculty $faculty): RedirectResponse
|
||||||
|
@ -59,6 +59,7 @@ class FacultyController extends Controller
|
||||||
$faculty->name = $validated['name'];
|
$faculty->name = $validated['name'];
|
||||||
$faculty->description = $validated['description'];
|
$faculty->description = $validated['description'];
|
||||||
$faculty->position = $validated['position'];
|
$faculty->position = $validated['position'];
|
||||||
|
$faculty->slug = $validated['slug'];
|
||||||
$faculty->educational_institution_id = $validated['educational_institution_id'];
|
$faculty->educational_institution_id = $validated['educational_institution_id'];
|
||||||
$faculty->save();
|
$faculty->save();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Requests\Catalog;
|
namespace App\Http\Requests\admin\Catalog;
|
||||||
|
|
||||||
use Illuminate\Contracts\Validation\ValidationRule;
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
@ -12,17 +12,13 @@ class StoreFacultyRequest extends FormRequest
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, ValidationRule|array|string>
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'position' => 'int|max:255',
|
'position' => 'int|max:255',
|
||||||
'name' => 'required|string|max:255|unique:educational_institutions,name',
|
'name' => 'required|string|max:255|unique:educational_institutions,name',
|
||||||
'description' => 'string',
|
'description' => 'string',
|
||||||
|
'slug' => 'required|string',
|
||||||
'educational_institution_id' => 'int'
|
'educational_institution_id' => 'int'
|
||||||
];
|
];
|
||||||
}
|
}
|
|
@ -1,30 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Requests\Catalog;
|
namespace App\Http\Requests\admin\Catalog;
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
class UpdateFacultyRequest extends FormRequest
|
class UpdateFacultyRequest extends FormRequest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*/
|
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return true;
|
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
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'position' => 'int|max:255',
|
'position' => 'int|max:255',
|
||||||
'name' => 'required|string|max:255|unique:educational_institutions,name',
|
'name' => 'required|string|max:255|unique:educational_institutions,name',
|
||||||
'description' => 'string',
|
'description' => 'string',
|
||||||
|
'slug' => 'required|string',
|
||||||
'educational_institution_id' => 'int'
|
'educational_institution_id' => 'int'
|
||||||
];
|
];
|
||||||
}
|
}
|
|
@ -15,6 +15,7 @@ class Faculty extends Model
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
|
'slug',
|
||||||
'position',
|
'position',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Policies;
|
|
||||||
|
|
||||||
use App\Models\Faculty;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Auth\Access\Response;
|
|
||||||
|
|
||||||
class FacultyPolicy
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 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, Faculty $faculty): 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, Faculty $faculty): bool
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine whether the user can delete the model.
|
|
||||||
*/
|
|
||||||
public function delete(User $user, Faculty $faculty): bool
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine whether the user can restore the model.
|
|
||||||
*/
|
|
||||||
public function restore(User $user, Faculty $faculty): bool
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine whether the user can permanently delete the model.
|
|
||||||
*/
|
|
||||||
public function forceDelete(User $user, Faculty $faculty): bool
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,7 +17,11 @@ class FacultyFactory extends Factory
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
//
|
'name' => fake()->name(),
|
||||||
|
'description' => fake()->text(),
|
||||||
|
'position' => fake()->randomDigit(),
|
||||||
|
'slug' => fake()->slug(),
|
||||||
|
'educational_institution_id' => 1,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ return new class extends Migration
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->string('description');
|
$table->string('description');
|
||||||
$table->integer('position');
|
$table->integer('position');
|
||||||
|
$table->string('slug');
|
||||||
$table->foreignId('educational_institution_id')->constrained('educational_institutions');
|
$table->foreignId('educational_institution_id')->constrained('educational_institutions');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,17 +14,20 @@ class FacultySeeder extends Seeder
|
||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
|
// Faculty::factory(3)->create();
|
||||||
DB::table('faculties')->insert([
|
DB::table('faculties')->insert([
|
||||||
[
|
[
|
||||||
'name' => 'Информационная безопасность',
|
'name' => 'Информационная безопасность',
|
||||||
'description' => 'Факультет информационной безопасности описание',
|
'description' => 'Факультет информационной безопасности описание',
|
||||||
'position' => 1,
|
'position' => 1,
|
||||||
|
'slug' => 'new-slug-inf',
|
||||||
'educational_institution_id' => 1,
|
'educational_institution_id' => 1,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'Лечебный факультет',
|
'name' => 'Лечебный факультет',
|
||||||
'description' => 'Факультет Лечебный описание',
|
'description' => 'Факультет Лечебный описание',
|
||||||
'position' => 1,
|
'position' => 1,
|
||||||
|
'slug' => 'new-slug-med',
|
||||||
'educational_institution_id' => 2,
|
'educational_institution_id' => 2,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
@extends('layouts.admin-layout')
|
@extends('layouts.admin-layout')
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
@auth()
|
@auth()
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
@ -53,6 +52,17 @@
|
||||||
{{ $errors->first('educational_institution_id') }}
|
{{ $errors->first('educational_institution_id') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</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">
|
<div class="mt-3">
|
||||||
{{ Form::submit('создать', ['class' => 'btn btn-primary']) }}
|
{{ Form::submit('создать', ['class' => 'btn btn-primary']) }}
|
||||||
</div>
|
</div>
|
|
@ -53,6 +53,17 @@
|
||||||
{{ $errors->first('educational_institution_id') }}
|
{{ $errors->first('educational_institution_id') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mt-3">
|
||||||
|
{{ Form::label('slug', 'URL') }}
|
||||||
|
</div>
|
||||||
|
<div class="mt-1">
|
||||||
|
{{ Form::text('slug', $faculty->slug, ['class' => 'form-control']) }}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
@if ($errors->any())
|
||||||
|
{{ $errors->first('slug') }}
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::submit('создать', ['class' => 'btn btn-primary']) }}
|
{{ Form::submit('создать', ['class' => 'btn btn-primary']) }}
|
||||||
</div>
|
</div>
|
|
@ -0,0 +1,109 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
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;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class FacultyTest extends TestCase
|
||||||
|
{
|
||||||
|
private User $user;
|
||||||
|
private Faculty $faculty;
|
||||||
|
private array $data;
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
EducationalInstitution::factory()->create();
|
||||||
|
|
||||||
|
$this->faculty = Faculty::factory()->create();
|
||||||
|
$this->data = Faculty::factory()->make()->only([
|
||||||
|
'position',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'slug',
|
||||||
|
'educational_institution_id',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->department = Department::factory()->create();
|
||||||
|
|
||||||
|
$this->user = User::factory()->create([
|
||||||
|
'name' => 'admin',
|
||||||
|
'email' => 'test@example.com',
|
||||||
|
'password' => 123456
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexFacultysPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('faculties.index'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateFacultyPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('faculties.create'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStoreFaculty(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->post(route('faculties.store', $this->data));
|
||||||
|
|
||||||
|
$response->assertRedirect(route('faculties.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('faculties', $this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testShowFacultyPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('faculties.show', $this->faculty));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEditFacultyPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('faculties.edit', $this->faculty));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateFaculty(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->patch(route('faculties.update', $this->faculty), $this->data);
|
||||||
|
|
||||||
|
$response->assertRedirect(route('faculties.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('faculties', $this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDestroyFaculty(): void
|
||||||
|
{
|
||||||
|
$this->department->delete();
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->delete(route('faculties.destroy', $this->faculty));
|
||||||
|
|
||||||
|
$response->assertRedirect(route('faculties.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('faculties', $this->faculty->toArray());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue