applicant-site/app/Http/Controllers/admin/Catalog/Direction/CostController.php

91 lines
2.6 KiB
PHP
Raw Normal View History

2024-02-26 09:37:27 +03:00
<?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');
}
}