Compare commits

..

2 Commits

Author SHA1 Message Date
aslan 1e804e1161 fix rename methods in PlaceController.php
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Successful in 2m12s Details
Tests & Lint & Deploy to Railway / deploy (push) Successful in 19s Details
2024-02-26 09:38:17 +03:00
aslan 115f49ea53 add Cost resource 2024-02-26 09:37:27 +03:00
20 changed files with 610 additions and 8 deletions

View File

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

View File

@ -62,7 +62,7 @@ class PlaceController extends Controller
$placeTypes = PlaceType::pluck('name', 'id');
$educationForms = EducationForm::pluck('name', 'id');
return view(
'admin.catalog.direction.place.create',
'admin.catalog.direction.place.edit',
compact(
'place',
'directions',

View File

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

View File

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

32
app/Models/Cost.php Normal file
View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,32 @@
<?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('costs', function (Blueprint $table) {
$table->id();
$table->integer('position');
$table->integer('cost');
$table->foreignId('education_form_id')->constrained('education_forms');
$table->foreignId('direction_id')->constrained('directions');
$table->text('description')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('costs');
}
};

View File

@ -0,0 +1,30 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class CostSeeder extends Seeder
{
public function run(): void
{
DB::table('costs')->insert([
[
'position' => 1,
'cost' => 103000,
'education_form_id' => 1,
'direction_id' => 1,
'description' => 'стоимость обучения 103 000 руб',
],
[
'position' => 2,
'cost' => 42000,
'education_form_id' => 2,
'direction_id' => 1,
'description' => 'стоимость обучения 42 000 руб',
],
]);
}
}

View File

@ -34,6 +34,7 @@ class DatabaseSeeder extends Seeder
EntranceExaminationSeeder::class,
PlaceTypeSeeder::class,
PlaceSeeder::class,
CostSeeder::class,
]);
$this->call([

View File

@ -0,0 +1,79 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Создать стоимость</h1>
{{ Form::open(['url' => route('costs.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('cost', 'стоимость') }}
</div>
<div class="mt-1">
{{ Form::text('cost', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('cost') }}
@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('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,79 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class="">Изменить Стоимость</h1>
{{ Form::open(['url' => route('costs.update', $cost), 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', $cost->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', $cost->description, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('cost', 'Количество мест') }}
</div>
<div class="mt-1">
{{ Form::text('cost', $cost->cost, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('cost') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('direction_id', 'Направление подготовки') }}
</div>
<div class="mt-1">
{{ Form::select('direction_id', $directions, $cost->direction->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('direction_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('education_form_id', 'Форма обучения') }}
</div>
<div class="mt-1">
{{ Form::select('education_form_id', $educationForms, $cost->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,45 @@
@extends('layouts.admin_layout')
@section('content')
<div class="container">
<h2>Стоимость</h2>
<br>
<a href="{{ route('costs.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>
</tr>
</thead>
<tbody>
@foreach($costs as $cost)
<tr class="">
<td>{{ $cost->position }}</td>
<td>{{ Str::words($cost->description, 10, '...') }}</td>
<td><a href="{{ route('education_forms.show', $cost->educationForm) }}">{{ $cost->educationForm->name }}</a></td>
<td><a href="{{ route('directions.show', $cost->direction) }}">{{ $cost->direction->name }}</a></td>
<td>{{ $cost->cost }}</td>
<td>
<a href="{{ route("costs.show", $cost) }}"
class="btn btn-info">посмотреть</a>
<a href="{{ route("costs.edit", $cost) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('costs.destroy', $cost) }}"
class="btn btn-danger">удалить</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<br>
<br>
</div>
@endsection

View File

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

View File

@ -71,7 +71,7 @@
{{ Form::label('education_form_id', 'Форма обучения') }}
</div>
<div class="mt-1">
{{ Form::select('education_form_id', $educationForm, $place->educationForm->id, ['class' => 'form-select']) }}
{{ Form::select('education_form_id', $educationForms, $place->educationForm->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())

View File

@ -64,6 +64,7 @@
<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>
<li class="list-group-item"><a href="{{ route('costs.index') }}">Стоимость об.</a></li>
</ul>
</aside>
<main class="col-10">@yield('content')</main>

View File

@ -2,6 +2,7 @@
use App\Http\Controllers\admin\AdmissionController;
use App\Http\Controllers\admin\Catalog\DepartmentController;
use App\Http\Controllers\admin\Catalog\Direction\CostController;
use App\Http\Controllers\admin\Catalog\Direction\EducationFormController;
use App\Http\Controllers\admin\Catalog\Direction\EducationLevelController;
use App\Http\Controllers\admin\Catalog\Direction\EntranceExaminationController;
@ -62,6 +63,7 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
->scoped(['place_type' => 'slug']);
Route::resource('/places', PlaceController::class);
Route::resource('/costs', CostController::class);
Route::resources([
'/documents' => DocumentController::class,

View File

@ -0,0 +1,117 @@
<?php
namespace Tests\Feature\admin\catalog\direction;
use App\Models\Cost;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\Faculty;
use App\Models\Place;
use App\Models\PlaceType;
use App\Models\User;
use Tests\TestCase;
class CostTest extends TestCase
{
private User $user;
private Cost $cost;
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
Department::factory()->create();
EducationLevel::factory()->create();
EducationForm::factory()->create();
Direction::factory()->create();
$this->cost = Cost::factory()->create();
$this->data = Cost::factory()->make()->only([
'position',
'description',
'cost',
'education_form_id',
'direction_id',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexCostsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('costs.index'));
$response->assertOk();
}
public function testCreateCostPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('costs.create'));
$response->assertOk();
}
public function testStoreCost(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('costs.store', $this->data));
$response->assertRedirect(route('costs.index'));
$this->assertDatabaseHas('costs', $this->data);
}
public function testShowCost(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('costs.show', $this->cost));
$response->assertOk();
}
public function testEditCostPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('costs.edit', $this->cost));
$response->assertOk();
}
public function testUpdateCost(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('costs.update', $this->cost), $this->data);
$response->assertRedirect(route('costs.index'));
$this->assertDatabaseHas('costs', $this->data);
}
public function testDestroyCost(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('costs.destroy', $this->cost));
$response->assertRedirect(route('costs.index'));
$this->assertDatabaseMissing('costs', $this->cost->toArray());
}
}

View File

@ -57,7 +57,7 @@ class PlaceTest extends TestCase
$response->assertOk();
}
public function testCreatePlaceTypePage(): void
public function testCreatePlacePage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
@ -66,7 +66,7 @@ class PlaceTest extends TestCase
$response->assertOk();
}
public function testStorePlaceType(): void
public function testStorePlace(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
@ -77,7 +77,7 @@ class PlaceTest extends TestCase
$this->assertDatabaseHas('places', $this->data);
}
public function testShowPlaceTypePage(): void
public function testShowPlacePage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
@ -86,7 +86,7 @@ class PlaceTest extends TestCase
$response->assertOk();
}
public function testEditPlaceTypePage(): void
public function testEditPlacePage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
@ -95,7 +95,7 @@ class PlaceTest extends TestCase
$response->assertOk();
}
public function testUpdatePlaceType(): void
public function testUpdatePlace(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
@ -106,7 +106,7 @@ class PlaceTest extends TestCase
$this->assertDatabaseHas('places', $this->data);
}
public function testDestroyPlaceType(): void
public function testDestroyPlace(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])