add Place and PlaceType resources

This commit is contained in:
aslan 2024-02-19 18:55:44 +03:00
parent 75452eff7d
commit 52dd465532
30 changed files with 1177 additions and 1 deletions

View File

@ -0,0 +1,93 @@
<?php
namespace App\Http\Controllers\admin\Catalog\Direction;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\Direction\StorePlaceRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdatePlaceRequest;
use App\Models\Direction;
use App\Models\EducationForm;
use App\Models\Place;
use App\Models\PlaceType;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
class PlaceController extends Controller
{
public function index(): View
{
$places = Place::all();
return view('admin.catalog.direction.place.index', compact('places'));
}
public function create(): View
{
$directions = Direction::pluck('name', 'id');
$placeTypes = PlaceType::pluck('name', 'id');
$educationForms = EducationForm::pluck('name', 'id');
return view(
'admin.catalog.direction.place.create',
compact(
'directions',
'placeTypes',
'educationForms',
));
}
public function store(StorePlaceRequest $request): RedirectResponse
{
$validated = $request->validated();
$place = new Place();
$place->position = $validated['position'];
$place->description = $validated['description'];
$place->amount = $validated['amount'];
$place->education_form_id = $validated['education_form_id'];
$place->place_type_id = $validated['place_type_id'];
$place->direction_id = $validated['direction_id'];
$place->save();
return redirect()->route('places.index');
}
public function show(Place $place): View
{
return view('admin.catalog.direction.place.show', compact('place'));
}
public function edit(Place $place): View
{
$directions = Direction::pluck('name', 'id');
$placeTypes = PlaceType::pluck('name', 'id');
$educationForms = EducationForm::pluck('name', 'id');
return view(
'admin.catalog.direction.place.create',
compact(
'place',
'directions',
'placeTypes',
'educationForms',
));
}
public function update(UpdatePlaceRequest $request, Place $place): RedirectResponse
{
$validated = $request->validated();
$place->position = $validated['position'];
$place->description = $validated['description'];
$place->amount = $validated['amount'];
$place->education_form_id = $validated['education_form_id'];
$place->place_type_id = $validated['place_type_id'];
$place->direction_id = $validated['direction_id'];
$place->save();
return redirect()->route('places.index');
}
public function destroy(Place $place): RedirectResponse
{
$place->delete();
return redirect()->route('places.index');
}
}

View File

@ -0,0 +1,72 @@
<?php
namespace App\Http\Controllers\admin\Catalog\Direction;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\Direction\StoreExaminationTypeRequest;
use App\Http\Requests\admin\Catalog\Direction\StorePlaceTypeRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdateExaminationTypeRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdatePlaceTypeRequest;
use App\Models\PlaceType;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
class PlaceTypeController extends Controller
{
public function index(): View
{
$placeTypes = PlaceType::all();
return view('admin.catalog.direction.place_type.index', compact('placeTypes'));
}
public function create(): View
{
return view('admin.catalog.direction.place_type.create');
}
public function store(StorePlaceTypeRequest $request): RedirectResponse
{
$validated = $request->validated();
$type = new PlaceType();
$type->name = $validated['name'];
$type->description = $validated['description'];
$type->slug = $validated['slug'];
$type->position = $validated['position'];
$type->save();
return redirect()->route('place_types.index');
}
public function show(PlaceType $placeType): View
{
return view('admin.catalog.direction.place_type.show', compact('placeType'));
}
public function edit(PlaceType $placeType): View
{
return view('admin.catalog.direction.place_type.edit', compact('placeType'));
}
public function update(UpdatePlaceTypeRequest $request, PlaceType $placeType): RedirectResponse
{
$validated = $request->validated();
$placeType->name = $validated['name'];
$placeType->description = $validated['description'];
$placeType->slug = $validated['slug'];
$placeType->position = $validated['position'];
$placeType->save();
return redirect()->route('place_types.index');
}
public function destroy(PlaceType $placeType): RedirectResponse
{
if ($placeType->places()->exists()) {
return back();
}
$placeType->delete();
return redirect()->route('place_types.index');
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Http\Requests\admin\Catalog\Direction;
use Illuminate\Foundation\Http\FormRequest;
class StorePlaceRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'position' => 'required|int|numeric|max:255',
'description' => 'string',
'amount' => 'required|int|numeric|max:255',
'education_form_id' => 'required|int|numeric|max:255',
'place_type_id' => 'required|int|numeric|max:255',
'direction_id' => 'required|int|numeric|max:255',
];
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\Http\Requests\admin\Catalog\Direction;
use Illuminate\Foundation\Http\FormRequest;
class StorePlaceTypeRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'position' => 'required|int|numeric|max:255',
'name' => 'required|string|max:255|unique:place_types,name',
'description' => 'string',
'slug' => 'required|string|max:255|unique:place_types,slug',
];
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Http\Requests\admin\Catalog\Direction;
use Illuminate\Foundation\Http\FormRequest;
class UpdatePlaceRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'position' => 'required|int|numeric|max:255',
'description' => 'string',
'amount' => 'required|int|numeric|max:255',
'education_form_id' => 'required|int|numeric|max:255',
'place_type_id' => 'required|int|numeric|max:255',
'direction_id' => 'required|int|numeric|max:255',
];
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests\admin\Catalog\Direction;
use Illuminate\Foundation\Http\FormRequest;
class UpdatePlaceTypeRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'position' => 'required|int|numeric|max:255',
'description' => 'string',
'slug' => [
'string',
'required',
'max:255',
"unique:place_types,slug,{$this->place_type->id}",
],
'name' => [
'required',
'string',
'max:255',
"unique:place_types,name,{$this->place_type->id}",
],
];
}
}

View File

@ -39,4 +39,9 @@ class Direction extends Model
{
return $this->hasMany('App\Models\EntranceExamination', 'direction_id');
}
public function places(): HasMany
{
return $this->hasMany('App\Models\Place', 'direction_id');
}
}

View File

@ -21,4 +21,9 @@ class EducationForm extends Model
{
return $this->hasMany('App\Models\Direction', 'education_form_id');
}
public function places(): HasMany
{
return $this->hasMany('App\Models\Place', 'education_form_id');
}
}

37
app/Models/Place.php Normal file
View File

@ -0,0 +1,37 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Place extends Model
{
use HasFactory;
protected $fillable = [
'id',
'position',
'description',
'amount',
'education_form_id',
'place_type_id',
'direction_id',
];
public function direction(): BelongsTo
{
return $this->belongsTo(Direction::class);
}
public function placeType(): BelongsTo
{
return $this->belongsTo(PlaceType::class);
}
public function educationForm(): BelongsTo
{
return $this->belongsTo(EducationForm::class);
}
}

25
app/Models/PlaceType.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class PlaceType extends Model
{
use HasFactory;
protected $fillable = [
'id',
'name',
'description',
'slug',
'position',
];
public function places(): HasMany
{
return $this->hasMany('App\Models\Place', 'place_type_id');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class PlaceFactory extends Factory
{
public function definition(): array
{
return [
'position' => 1,
'description' => fake()->text(),
'amount' => fake()->randomDigit(),
'education_form_id' => 1,
'place_type_id' => 1,
'direction_id' => 1,
];
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class PlaceTypeFactory extends Factory
{
public function definition(): array
{
return [
'name' => fake()->name(),
'description' => fake()->text(),
'slug' => fake()->slug(),
'position' => '1',
];
}
}

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('place_types', function (Blueprint $table) {
$table->id();
$table->integer('position');
$table->string('name');
$table->text('description')->nullable();
$table->string('slug');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('place_types');
}
};

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('places', function (Blueprint $table) {
$table->id();
$table->integer('position');
$table->integer('amount');
$table->foreignId('education_form_id')->constrained('education_forms');
$table->foreignId('place_type_id')->constrained('place_types');
$table->foreignId('direction_id')->constrained('directions');
$table->text('description')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('places');
}
};

View File

@ -32,6 +32,8 @@ class DatabaseSeeder extends Seeder
SubjectTypeSeeder::class,
DirectionSeeder::class,
EntranceExaminationSeeder::class,
PlaceTypeSeeder::class,
PlaceSeeder::class,
]);
$this->call([

View File

@ -0,0 +1,32 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class PlaceSeeder extends Seeder
{
public function run(): void
{
DB::table('places')->insert([
[
'position' => 1,
'amount' => 25,
'education_form_id' => 1,
'place_type_id' => 1,
'direction_id' => 1,
'description' => 'очная бюджетная форма 25 мест юриспруденция',
],
[
'position' => 2,
'amount' => 30,
'education_form_id' => 2,
'place_type_id' => 2,
'direction_id' => 1,
'description' => 'заочная платная форма 30 мест юриспруденция',
],
]);
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class PlaceTypeSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
DB::table('place_types')->insert([
[
'name' => 'бюджетная',
'description' => 'бюджетная',
'slug' => 'budget',
'position' => '1',
],
[
'name' => 'платная',
'description' => 'платная',
'slug' => 'paid',
'position' => '2',
],
]);
}
}

View File

@ -0,0 +1,91 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Создать места</h1>
{{ Form::open(['url' => route('places.store'), 'method' => 'POST', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('description', 'Описание') }}
</div>
<div class="mt-1">
{{ Form::text('description', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('amount', 'Количество мест') }}
</div>
<div class="mt-1">
{{ Form::text('amount', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('amount') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('direction_id', 'Направление подготовки') }}
</div>
<div class="mt-1">
{{ Form::select('direction_id', $directions, null, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('direction_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('place_type_id', 'Тип места') }}
</div>
<div class="mt-1">
{{ Form::select('place_type_id', $placeTypes, null, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('place_type_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('education_form_id', 'Форма обучения') }}
</div>
<div class="mt-1">
{{ Form::select('education_form_id', $educationForms, null, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('education_form_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,91 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class="">Изменить место</h1>
{{ Form::open(['url' => route('places.update', $place), 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', $place->position, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('description', 'Описание') }}
</div>
<div class="mt-1">
{{ Form::text('description', $place->description, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('amount', 'Количество мест') }}
</div>
<div class="mt-1">
{{ Form::text('amount', $place->amount, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('amount') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('direction_id', 'Направление подготовки') }}
</div>
<div class="mt-1">
{{ Form::select('direction_id', $directions, $place->direction->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('direction_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('place_type_id', 'Тип места') }}
</div>
<div class="mt-1">
{{ Form::select('place_type_id', $placeTypes, $place->placeType->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('place_type_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('education_form_id', 'Форма обучения') }}
</div>
<div class="mt-1">
{{ Form::select('education_form_id', $educationForm, $place->educationForm->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('education_form_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,47 @@
@extends('layouts.admin_layout')
@section('content')
<div class="container">
<h2>Места</h2>
<br>
<a href="{{ route('places.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">Тип места</th>
<th scope="col">направление</th>
<th scope="col">Кол-во</th>
<th scope="col">действия</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach($places as $place)
<tr class="">
<td>{{ $place->position }}</td>
<td>{{ Str::words($place->description, 10, '...') }}</td>
<td><a href="{{ route('education_forms.show', $place->educationForm) }}">{{ $place->educationForm->name }}</a></td>
<td><a href="{{ route('place_types.show', $place->placeType) }}">{{ $place->placeType->name }}</a></td>
<td><a href="{{ route('directions.show', $place->direction) }}">{{ $place->direction->name }}</a></td>
<td>{{ $place->amount }}</td>
<td>
<a href="{{ route("places.show", $place) }}"
class="btn btn-info">посмотреть</a>
<a href="{{ route("places.edit", $place) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('places.destroy', $place) }}"
class="btn btn-danger">удалить</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<br>
<br>
</div>
@endsection

View File

@ -0,0 +1,19 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="container mt-4">
<h2>позиция</h2>
<p>{{ $place->position }}</p>
<h2>описание</h2>
<p>{{ $place->description }}</p>
<h2>Форма обучения</h2>
<p>{{ $place->educationForm->name }}</p>
<h2>Тип Места</h2>
<p>{{ $place->placeType->name }}</p>
<h2>Направление</h2>
<p>{{ $place->direction->name }}</p>
<h2>Кол-во</h2>
<p>{{ $place->amount }}</p>
</div>
@endauth
@endsection

View File

@ -0,0 +1,65 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Создать тип Места</h1>
{{ Form::open(['url' => route('place_types.store'), 'method' => 'POST', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('name', 'Название') }}
</div>
<div class="mt-1">
{{ Form::text('name', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('name') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('description', 'Описание') }}
</div>
<div class="mt-1">
{{ Form::text('description', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $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-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,66 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class="">Изменить тип экзамена</h1>
{{ Form::open(['url' => route('place_types.update', $placeType), 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('name', 'Название') }}
</div>
<div class="mt-1">
{{ Form::text('name', $placeType->name, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('name') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('description', 'Описание') }}
</div>
<div class="mt-1">
{{ Form::text('description', $placeType->description, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('slug', 'URL') }}
</div>
<div class="mt-1">
{{ Form::text('slug', $placeType->slug, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('slug') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', $placeType->position, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,41 @@
@extends('layouts.admin_layout')
@section('content')
<div class="container">
<h2>Тип Места</h2>
<br>
<a href="{{ route('place_types.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>
</thead>
<tbody>
@foreach($placeTypes as $placeType)
<tr class="">
<td>{{ $placeType->position }}</td>
<td><a href="{{ route('place_types.show', $placeType) }}">{{ $placeType->name }}</a></td>
<td>{{ Str::words($placeType->description, 10, '...') }}</td>
<td>{{ $placeType->slug }}</td>
<td>
<a href="{{ route("place_types.edit", $placeType) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('place_types.destroy', $placeType) }}"
class="btn btn-danger">удалить</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<br>
<br>
</div>
@endsection

View File

@ -0,0 +1,19 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="container mt-4">
<h2>Название</h2>
<p>{{ $placeType->name }}</p>
<h2>Описание</h2>
<p>{{ $placeType->description }}</p>
<h2>URL</h2>
<p>{{ $placeType->slug }}</p>
<h2>Позиция</h2>
<p>{{ $placeType->position }}</p>
<h2>Места</h2>
@foreach($placeType->places as $place)
<p><a href="{{ route('places.show', $place) }}">{{ $place->name }}</a></p>
@endforeach
</div>
@endauth
@endsection

View File

@ -62,6 +62,8 @@
<li class="list-group-item"><a href="{{ route('examination_types.index') }}">Типы Экзаменов</a></li>
<li class="list-group-item"><a href="{{ route('subjects.index') }}">Предметы</a></li>
<li class="list-group-item"><a href="{{ route('subject_types.index') }}">Типы Предметов</a></li>
<li class="list-group-item"><a href="{{ route('places.index') }}">Кол-во Мест</a></li>
<li class="list-group-item"><a href="{{ route('place_types.index') }}">Типы Мест</a></li>
</ul>
</aside>
<main class="col-10">@yield('content')</main>

View File

@ -6,6 +6,8 @@ use App\Http\Controllers\admin\Catalog\Direction\EducationFormController;
use App\Http\Controllers\admin\Catalog\Direction\EducationLevelController;
use App\Http\Controllers\admin\Catalog\Direction\EntranceExaminationController;
use App\Http\Controllers\admin\Catalog\Direction\ExaminationTypeController;
use App\Http\Controllers\admin\Catalog\Direction\PlaceController;
use App\Http\Controllers\admin\Catalog\Direction\PlaceTypeController;
use App\Http\Controllers\admin\Catalog\Direction\SubjectController;
use App\Http\Controllers\admin\Catalog\Direction\SubjectTypeController;
use App\Http\Controllers\admin\Catalog\DirectionController;
@ -56,6 +58,11 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
Route::resource('/entrance_examinations', EntranceExaminationController::class);
Route::resource('/place_types', PlaceTypeController::class)
->scoped(['place_type' => 'slug']);
Route::resource('/places', PlaceController::class);
Route::resources([
'/documents' => DocumentController::class,
'/users' => UserController::class,

View File

@ -92,7 +92,7 @@ class EducationalInstitutionTest extends TestCase
$this->assertDatabaseHas('educational_institutions', $this->data);
}
public function testDestroyFaculty(): void
public function testDestroyEducationalInstitution(): void
{
$this->faculty->delete();
$response = $this->actingAs($this->user)

View File

@ -0,0 +1,119 @@
<?php
namespace Tests\Feature\admin\catalog\direction;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\EntranceExamination;
use App\Models\Faculty;
use App\Models\Place;
use App\Models\PlaceType;
use App\Models\User;
use Tests\TestCase;
class PlaceTest extends TestCase
{
private User $user;
private Place $place;
private array $data;
protected function setUp(): void
{
parent::setUp();
PlaceType::factory()->create();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
Department::factory()->create();
EducationLevel::factory()->create();
EducationForm::factory()->create();
Direction::factory()->create();
$this->place = Place::factory()->create();
$this->data = Place::factory()->make()->only([
'position',
'description',
'amount',
'education_form_id',
'place_type_id',
'direction_id',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexPlacesPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('places.index'));
$response->assertOk();
}
public function testCreatePlaceTypePage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('places.create'));
$response->assertOk();
}
public function testStorePlaceType(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('places.store', $this->data));
$response->assertRedirect(route('places.index'));
$this->assertDatabaseHas('places', $this->data);
}
public function testShowPlaceTypePage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('places.show', $this->place));
$response->assertOk();
}
public function testEditPlaceTypePage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('places.edit', $this->place));
$response->assertOk();
}
public function testUpdatePlaceType(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('places.update', $this->place), $this->data);
$response->assertRedirect(route('places.index'));
$this->assertDatabaseHas('places', $this->data);
}
public function testDestroyPlaceType(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('places.destroy', $this->place));
$response->assertRedirect(route('places.index'));
$this->assertDatabaseMissing('places', $this->place->toArray());
}
}

View File

@ -0,0 +1,102 @@
<?php
namespace Tests\Feature\admin\catalog\direction;
use App\Models\ExaminationType;
use App\Models\PlaceType;
use App\Models\User;
use Tests\TestCase;
class PlaceTypeTest extends TestCase
{
private User $user;
private PlaceType $type;
private array $data;
protected function setUp(): void
{
parent::setUp();
$this->type = PlaceType::factory()->create();
$this->data = PlaceType::factory()->make()->only([
'name',
'description',
'position',
'slug',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexPlaceTypesPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('place_types.index'));
$response->assertOk();
}
public function testCreatePlaceTypePage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('place_types.create'));
$response->assertOk();
}
public function testStorePlaceType(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('place_types.store', $this->data));
$response->assertRedirect(route('place_types.index'));
$this->assertDatabaseHas('place_types', $this->data);
}
public function testShowPlaceTypePage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('place_types.show', $this->type));
$response->assertOk();
}
public function testEditPlaceTypePage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('place_types.edit', $this->type));
$response->assertOk();
}
public function testUpdatePlaceType(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('place_types.update', $this->type), $this->data);
$response->assertRedirect(route('place_types.index'));
$this->assertDatabaseHas('place_types', $this->data);
}
public function testDestroyPlaceType(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('place_types.destroy', $this->type));
$response->assertRedirect(route('place_types.index'));
$this->assertDatabaseMissing('place_types', $this->type->toArray());
}
}