2024-02-26 10:58:02 +03:00
|
|
|
<?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->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',
|
2024-02-26 10:58:36 +03:00
|
|
|
compact('directionProfile', 'directions')
|
2024-02-26 10:58:02 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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->save();
|
|
|
|
|
|
|
|
return redirect()->route('direction_profiles.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(DirectionProfile $directionProfile): RedirectResponse
|
|
|
|
{
|
2024-03-05 15:38:09 +03:00
|
|
|
if ($directionProfile->direction()->exists()) {
|
|
|
|
return back();
|
|
|
|
}
|
2024-02-26 10:58:02 +03:00
|
|
|
$directionProfile->delete();
|
|
|
|
return redirect()->route('direction_profiles.index');
|
|
|
|
}
|
|
|
|
}
|