89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin\Catalog\Direction;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\admin\Catalog\Direction\StorePeriodRequest;
|
|
use App\Http\Requests\admin\Catalog\Direction\UpdatePeriodRequest;
|
|
use App\Models\Direction;
|
|
use App\Models\EducationForm;
|
|
use App\Models\Period;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
class PeriodController extends Controller
|
|
{
|
|
public function index(): View
|
|
{
|
|
$periods = Period::all();
|
|
return view('admin.catalog.direction.period.index', compact('periods'));
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
$directions = Direction::pluck('name', 'id');
|
|
$educationForms = EducationForm::pluck('name', 'id');
|
|
return view(
|
|
'admin.catalog.direction.period.create',
|
|
compact(
|
|
'directions',
|
|
'educationForms',
|
|
)
|
|
);
|
|
}
|
|
|
|
public function store(StorePeriodRequest $request): RedirectResponse
|
|
{
|
|
$validated = $request->validated();
|
|
|
|
$period = new Period();
|
|
$period->position = $validated['position'];
|
|
$period->description = $validated['description'];
|
|
$period->period = $validated['period'];
|
|
$period->education_form_id = $validated['education_form_id'];
|
|
$period->direction_id = $validated['direction_id'];
|
|
$period->save();
|
|
|
|
return redirect()->route('periods.index');
|
|
}
|
|
|
|
public function show(Period $period): View
|
|
{
|
|
return view('admin.catalog.direction.period.show', compact('period'));
|
|
}
|
|
|
|
public function edit(Period $period): View
|
|
{
|
|
$directions = Direction::pluck('name', 'id');
|
|
$educationForms = EducationForm::pluck('name', 'id');
|
|
return view(
|
|
'admin.catalog.direction.period.edit',
|
|
compact(
|
|
'period',
|
|
'directions',
|
|
'educationForms',
|
|
)
|
|
);
|
|
}
|
|
|
|
public function update(UpdatePeriodRequest $request, Period $period): RedirectResponse
|
|
{
|
|
$validated = $request->validated();
|
|
|
|
$period->position = $validated['position'];
|
|
$period->description = $validated['description'];
|
|
$period->period = $validated['period'];
|
|
$period->education_form_id = $validated['education_form_id'];
|
|
$period->direction_id = $validated['direction_id'];
|
|
$period->save();
|
|
|
|
return redirect()->route('periods.index');
|
|
}
|
|
|
|
public function destroy(Period $period): RedirectResponse
|
|
{
|
|
$period->delete();
|
|
return redirect()->route('periods.index');
|
|
}
|
|
}
|