validated(); if ($validated['slug'] === null) { $transliterationSlug = Str::slug($validated['name']); $randomNumber = random_int(100, 999); $slug = "{$transliterationSlug}-{$randomNumber}"; } else { $slug = $validated['slug']; } $directionProfile = new DirectionProfile(); $directionProfile->name = $validated['name']; $directionProfile->description = $validated['description']; $directionProfile->slug = $slug; $directionProfile->position = $validated['position']; $directionProfile->save(); Log::channel('app') ->info( 'CREATE профиль подготовки {directionProfile} - user {user}', ['user' => Auth::user()->name, 'directionProfile' => $directionProfile->name, 'data' => $validated] ); 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(); $oldData = $directionProfile->toArray(); $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 ] ); return redirect()->route('direction_profiles.index'); } public function destroy(DirectionProfile $directionProfile): RedirectResponse { if ($directionProfile->direction()->exists()) { Log::channel('app') ->error( 'NOT DELETE профиль подготовки {directionProfile} - user {user}', [ 'user' => Auth::user()->name, 'directionProfile' => $directionProfile->name, 'data' => $directionProfile->toArray(), ] ); return back(); } Log::channel('app') ->critical( 'DELETE профиль подготовки {directionProfile} - user {user}', [ 'user' => Auth::user()->name, 'directionProfile' => $directionProfile->name, 'data' => $directionProfile->toArray(), ] ); $directionProfile->delete(); return redirect()->route('direction_profiles.index'); } }