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

119 lines
4.2 KiB
PHP
Raw Permalink Normal View History

2024-02-26 10:58:02 +03:00
<?php
namespace App\Http\Controllers\admin\Catalog\Direction;
2024-03-12 12:40:40 +03:00
use App\Helpers\SlugHelper;
2024-02-26 10:58:02 +03:00
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;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
2024-02-26 10:58:02 +03:00
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();
2024-03-12 12:40:40 +03:00
$slug = SlugHelper::get($validated);
2024-02-26 10:58:02 +03:00
$directionProfile = new DirectionProfile();
$directionProfile->name = $validated['name'];
$directionProfile->description = $validated['description'];
$directionProfile->slug = $slug;
2024-02-26 10:58:02 +03:00
$directionProfile->position = $validated['position'];
$directionProfile->save();
Log::channel('app')
->info(
'CREATE профиль подготовки {directionProfile} - user {user}',
['user' => Auth::user()->name, 'directionProfile' => $directionProfile->name, 'data' => $validated]
);
2024-02-26 10:58:02 +03:00
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();
$oldData = $directionProfile->toArray();
2024-02-26 10:58:02 +03:00
$directionProfile->name = $validated['name'];
$directionProfile->description = $validated['description'];
$directionProfile->slug = $validated['slug'];
$directionProfile->position = $validated['position'];
$directionProfile->save();
Log::channel('app')
->warning(
'UPDATE профиль подготовки {directionProfile} - user {user}',
[
'user' => Auth::user()->name,
'directionProfile' => $directionProfile->name,
'oldData' => $oldData,
'newData' => $validated
]
);
2024-02-26 10:58:02 +03:00
return redirect()->route('direction_profiles.index');
}
public function destroy(DirectionProfile $directionProfile): RedirectResponse
{
2024-03-05 15:38:09 +03:00
if ($directionProfile->direction()->exists()) {
Log::channel('app')
->error(
'NOT DELETE профиль подготовки {directionProfile} - user {user}',
[
'user' => Auth::user()->name,
'directionProfile' => $directionProfile->name,
'data' => $directionProfile->toArray(),
]
);
2024-03-05 15:38:09 +03:00
return back();
}
Log::channel('app')
->critical(
'DELETE профиль подготовки {directionProfile} - user {user}',
[
'user' => Auth::user()->name,
'directionProfile' => $directionProfile->name,
'data' => $directionProfile->toArray(),
]
);
2024-02-26 10:58:02 +03:00
$directionProfile->delete();
return redirect()->route('direction_profiles.index');
}
}