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

76 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\StoreDirectionProfileRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdateDirectionProfileRequest;
use App\Models\Direction;
use App\Models\DirectionProfile;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
class DirectionProfileController extends Controller
{
public function index(): View
{
$directionProfiles = DirectionProfile::all();
return view('admin.catalog.direction.direction_profile.index', compact('directionProfiles'));
}
public function create(): View
{
$directions = Direction::pluck('name', 'id');
return view('admin.catalog.direction.direction_profile.create', compact('directions'));
}
public function store(StoreDirectionProfileRequest $request): RedirectResponse
{
$validated = $request->validated();
$directionProfile = new DirectionProfile();
$directionProfile->name = $validated['name'];
$directionProfile->description = $validated['description'];
$directionProfile->slug = $validated['slug'];
$directionProfile->position = $validated['position'];
$directionProfile->direction_id = $validated['direction_id'];
$directionProfile->save();
return redirect()->route('direction_profiles.index');
}
public function show(DirectionProfile $directionProfile): View
{
return view('admin.catalog.direction.direction_profile.show', compact('directionProfile'));
}
public function edit(DirectionProfile $directionProfile): View
{
$directions = Direction::pluck('name', 'id');
return view(
'admin.catalog.direction.direction_profile.edit',
compact('directionProfile','directions')
);
}
public function update(UpdateDirectionProfileRequest $request, DirectionProfile $directionProfile): RedirectResponse
{
$validated = $request->validated();
$directionProfile->name = $validated['name'];
$directionProfile->description = $validated['description'];
$directionProfile->slug = $validated['slug'];
$directionProfile->position = $validated['position'];
$directionProfile->direction_id = $validated['direction_id'];
$directionProfile->save();
return redirect()->route('direction_profiles.index');
}
public function destroy(DirectionProfile $directionProfile): RedirectResponse
{
$directionProfile->delete();
return redirect()->route('direction_profiles.index');
}
}