add logging to faculty
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Failing after 1m36s Details

This commit is contained in:
aslan 2024-03-11 14:34:23 +03:00
parent b9c143bab5
commit 3c37c2b903
2 changed files with 17 additions and 2 deletions

View File

@ -11,6 +11,8 @@ use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str; use Illuminate\Support\Str;
class FacultyController extends Controller class FacultyController extends Controller
@ -47,6 +49,10 @@ class FacultyController extends Controller
$faculty->educational_institution_id = $validated['educational_institution_id']; $faculty->educational_institution_id = $validated['educational_institution_id'];
$faculty->save(); $faculty->save();
Log::channel('app')
->info('CREATE факультет {faculty} - user {user}',
['user' => Auth::user()->name, 'faculty' => $faculty->name, 'data' => $validated]);
return redirect()->route('faculties.index'); return redirect()->route('faculties.index');
} }
@ -64,19 +70,28 @@ class FacultyController extends Controller
public function update(UpdateFacultyRequest $request, Faculty $faculty): RedirectResponse public function update(UpdateFacultyRequest $request, Faculty $faculty): RedirectResponse
{ {
$validated = $request->validated(); $validated = $request->validated();
$oldData = $faculty->toArray();
$faculty->name = $validated['name']; $faculty->name = $validated['name'];
$faculty->description = $validated['description']; $faculty->description = $validated['description'];
$faculty->position = $validated['position']; $faculty->position = $validated['position'];
$faculty->slug = $validated['slug']; $faculty->slug = $validated['slug'];
$faculty->educational_institution_id = $validated['educational_institution_id']; $faculty->educational_institution_id = $validated['educational_institution_id'];
$faculty->save();
Log::channel('app')
->info('UPDATE факультет {faculty} - user {user}',
['user' => Auth::user()->name, 'faculty' => $faculty->name, 'oldData' => $oldData, 'newData' => $validated]);
$faculty->save();
return redirect()->route('faculties.index'); return redirect()->route('faculties.index');
} }
public function destroy(Faculty $faculty): RedirectResponse public function destroy(Faculty $faculty): RedirectResponse
{ {
Log::channel('app')
->info('DELETE факультет {faculty} - user {user}',
['user' => Auth::user()->name, 'faculty' => $faculty->name, 'data' => $faculty->toArray()]);
if ($faculty->departments()->exists()) { if ($faculty->departments()->exists()) {
return back(); return back();
} }

View File

@ -18,7 +18,7 @@ class StoreFacultyRequest extends FormRequest
'position' => 'required|int|numeric|max:255', 'position' => 'required|int|numeric|max:255',
'name' => 'required|string|max:255|unique:faculties,name', 'name' => 'required|string|max:255|unique:faculties,name',
'description' => 'nullable|string', 'description' => 'nullable|string',
'slug' => 'nullable|string|max:255', 'slug' => 'nullable|string|max:255|unique:faculties,slug',
'educational_institution_id' => 'required|int|numeric|max:1000' 'educational_institution_id' => 'required|int|numeric|max:1000'
]; ];
} }