forked from aslan/applicant-site
add logging to faculty
This commit is contained in:
parent
b9c143bab5
commit
3c37c2b903
|
@ -11,6 +11,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;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FacultyController extends Controller
|
||||
|
@ -47,6 +49,10 @@ class FacultyController extends Controller
|
|||
$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');
|
||||
}
|
||||
|
||||
|
@ -64,19 +70,28 @@ class FacultyController extends Controller
|
|||
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'];
|
||||
$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');
|
||||
}
|
||||
|
||||
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()) {
|
||||
return back();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class StoreFacultyRequest extends FormRequest
|
|||
'position' => 'required|int|numeric|max:255',
|
||||
'name' => 'required|string|max:255|unique:faculties,name',
|
||||
'description' => 'nullable|string',
|
||||
'slug' => 'nullable|string|max:255',
|
||||
'slug' => 'nullable|string|max:255|unique:faculties,slug',
|
||||
'educational_institution_id' => 'required|int|numeric|max:1000'
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue