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

96 lines
2.9 KiB
PHP

<?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');
}
}