add Logging to DirectionController
This commit is contained in:
parent
ec57a7bd02
commit
54901c7ed5
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers\admin\Catalog;
|
||||
|
||||
use App\Enums\ExaminationTypeEnum;
|
||||
use App\Helpers\SlugHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
|
||||
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
|
||||
|
@ -20,6 +21,8 @@ use Illuminate\Contracts\View\Factory;
|
|||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DirectionController extends Controller
|
||||
{
|
||||
|
@ -56,12 +59,14 @@ class DirectionController extends Controller
|
|||
{
|
||||
|
||||
$validated = $request->validated();
|
||||
$slug = SlugHelper::get($validated);
|
||||
|
||||
$direction = new Direction();
|
||||
$direction->name = $validated['name'];
|
||||
$direction->full_name = "{$validated['code']} {$validated['name']}";
|
||||
$direction->description = $validated['description'];
|
||||
$direction->position = $validated['position'];
|
||||
$direction->slug = $validated['slug'];
|
||||
$direction->slug = $slug;
|
||||
$direction->code = $validated['code'];
|
||||
$direction->education_level_id = $validated['education_level_id'];
|
||||
$direction->education_form_id = $validated['education_form_id'];
|
||||
|
@ -92,6 +97,15 @@ class DirectionController extends Controller
|
|||
$direction->directionProfiles()->attach($validated['direction_profiles']);
|
||||
}
|
||||
|
||||
Log::channel('app')
|
||||
->info(
|
||||
'CREATE напр. подготовки {direction} - user {user}',
|
||||
[
|
||||
'user' => Auth::user()->name,
|
||||
'direction' => $direction->name,
|
||||
'data' => $validated
|
||||
]
|
||||
);
|
||||
return redirect()->route('directions.index');
|
||||
}
|
||||
|
||||
|
@ -158,7 +172,9 @@ class DirectionController extends Controller
|
|||
|
||||
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
|
||||
{
|
||||
$oldData = $direction->toArray();
|
||||
$validated = $request->validated();
|
||||
|
||||
$direction->name = $validated['name'];
|
||||
$direction->full_name = "{$validated['code']} {$validated['name']}";
|
||||
$direction->description = $validated['description'];
|
||||
|
@ -173,6 +189,18 @@ class DirectionController extends Controller
|
|||
$direction->paid_places = $validated['paid_places'];
|
||||
$direction->cost_paid_place = $validated['cost_paid_place'];
|
||||
$direction->period = $validated['period'];
|
||||
|
||||
Log::channel('app')
|
||||
->warning(
|
||||
'UPDATE напр. подготовки {direction} - user {user}',
|
||||
[
|
||||
'user' => Auth::user()->name,
|
||||
'direction' => $direction->name,
|
||||
'oldData' => $oldData,
|
||||
'newData' => $validated
|
||||
]
|
||||
);
|
||||
|
||||
$direction->save();
|
||||
|
||||
if (array_key_exists('entrance-examination', $validated)) {
|
||||
|
@ -188,7 +216,7 @@ class DirectionController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
// dd($validated);
|
||||
|
||||
if (array_key_exists('delete', $validated)) {
|
||||
foreach ($validated['delete'] as $id => $value) {
|
||||
$entranceExamination = EntranceExamination::firstOrNew(['id' => $id]);
|
||||
|
@ -207,8 +235,27 @@ class DirectionController extends Controller
|
|||
public function destroy(Direction $direction): RedirectResponse
|
||||
{
|
||||
if ($direction->entranceExaminations()->exists()) {
|
||||
Log::channel('app')
|
||||
->error(
|
||||
'NOT DELETE напр. подготовки {direction} - user {user}',
|
||||
[
|
||||
'user' => Auth::user()->name,
|
||||
'direction' => $direction->name,
|
||||
'data' => $direction->toArray(),
|
||||
]
|
||||
);
|
||||
return back();
|
||||
}
|
||||
|
||||
Log::channel('app')
|
||||
->critical(
|
||||
'DELETE напр. подготовки {direction} - user {user}',
|
||||
[
|
||||
'user' => Auth::user()->name,
|
||||
'direction' => $direction->name,
|
||||
'data' => $direction->toArray(),
|
||||
]
|
||||
);
|
||||
$direction->directionProfiles()->detach();
|
||||
$direction->delete();
|
||||
return redirect()->route('directions.index');
|
||||
|
@ -248,6 +295,16 @@ class DirectionController extends Controller
|
|||
|
||||
$newDirection->directionProfiles()->attach($direction->directionProfiles);
|
||||
|
||||
Log::channel('app')
|
||||
->info(
|
||||
'DUPLICATE напр. подготовки {direction} - user {user}',
|
||||
[
|
||||
'user' => Auth::user()->name,
|
||||
'direction' => $direction->name,
|
||||
'data' => $direction->toArray(),
|
||||
]
|
||||
);
|
||||
|
||||
return redirect()->route('directions.index');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue