validated(); if ($validated['slug'] === null) { $transliterationSlug = Str::slug($validated['name']); $randomNumber = random_int(100, 999); $slug = "{$transliterationSlug}-{$randomNumber}"; } else { $slug = $validated['slug']; } $faculty = new Faculty(); $faculty->name = $validated['name']; $faculty->description = $validated['description']; $faculty->position = $validated['position']; $faculty->slug = $slug; $faculty->educational_institution_id = $validated['educational_institution_id']; $faculty->save(); Log::channel('app') ->info( 'CREATE факультет {faculty} - user {user}', ['user' => Auth::user()->name, 'faculty' => $faculty->name, 'data' => $validated] ); return redirect()->route('faculties.index'); } public function show(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application { return view('admin.catalog.faculty.show', compact('faculty')); } public function edit(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application { $educationalInstitutions = EducationalInstitution::pluck('name', 'id'); return view('admin.catalog.faculty.edit', compact('faculty', 'educationalInstitutions')); } public function update(UpdateFacultyRequest $request, Faculty $faculty): RedirectResponse { $validated = $request->validated(); $oldData = $faculty->toArray(); $faculty->name = $validated['name']; $faculty->description = $validated['description']; $faculty->position = $validated['position']; $faculty->slug = $validated['slug']; $faculty->educational_institution_id = $validated['educational_institution_id']; Log::channel('app') ->warning( 'UPDATE факультет {faculty} - user {user}', [ 'user' => Auth::user()->name, 'faculty' => $faculty->name, 'oldData' => $oldData, 'newData' => $validated ] ); $faculty->save(); return redirect()->route('faculties.index'); } public function destroy(Faculty $faculty): RedirectResponse { if ($faculty->departments()->exists()) { Log::channel('app') ->critical( 'NOT DELETE факультет {faculty} - user {user}', [ 'user' => Auth::user()->name, 'faculty' => $faculty->name, 'data' => $faculty->toArray(), ] ); return back(); } Log::channel('app') ->critical( 'DELETE факультет {faculty} - user {user}', [ 'user' => Auth::user()->name, 'faculty' => $faculty->name, 'data' => $faculty->toArray(), ] ); $faculty->delete(); return redirect()->route('faculties.index'); } }