2024-02-17 11:30:32 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\admin\Catalog\Direction;
|
|
|
|
|
2024-03-12 13:50:42 +03:00
|
|
|
use App\Helpers\SlugHelper;
|
2024-02-17 11:30:32 +03:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Requests\admin\Catalog\Direction\StoreSubjectRequest;
|
|
|
|
use App\Http\Requests\admin\Catalog\Direction\UpdateSubjectRequest;
|
|
|
|
use App\Models\Subject;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2024-03-12 13:50:42 +03:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2024-02-17 11:30:32 +03:00
|
|
|
|
|
|
|
class SubjectController extends Controller
|
|
|
|
{
|
|
|
|
public function index(): View
|
|
|
|
{
|
|
|
|
$subjects = Subject::all();
|
|
|
|
return view('admin.catalog.direction.subject.index', compact('subjects'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create(): View
|
|
|
|
{
|
|
|
|
return view('admin.catalog.direction.subject.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store(StoreSubjectRequest $request): RedirectResponse
|
|
|
|
{
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
2024-03-12 13:50:42 +03:00
|
|
|
$slug = SlugHelper::get($validated);
|
|
|
|
|
2024-02-17 11:30:32 +03:00
|
|
|
$subject = new Subject();
|
|
|
|
$subject->name = $validated['name'];
|
|
|
|
$subject->description = $validated['description'];
|
2024-03-12 13:50:42 +03:00
|
|
|
$subject->slug = $slug;
|
2024-02-17 11:30:32 +03:00
|
|
|
$subject->position = $validated['position'];
|
|
|
|
$subject->save();
|
|
|
|
|
2024-03-12 13:50:42 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->info(
|
|
|
|
'CREATE предмет {subject} - user {user}',
|
|
|
|
['user' => Auth::user()->name, 'faculty' => $subject->name, 'data' => $validated]
|
|
|
|
);
|
|
|
|
|
2024-02-17 11:30:32 +03:00
|
|
|
return redirect()->route('subjects.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Subject $subject): View
|
|
|
|
{
|
|
|
|
return view('admin.catalog.direction.subject.show', compact('subject'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(Subject $subject): View
|
|
|
|
{
|
|
|
|
return view('admin.catalog.direction.subject.edit', compact('subject'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(UpdateSubjectRequest $request, Subject $subject): RedirectResponse
|
|
|
|
{
|
|
|
|
$validated = $request->validated();
|
2024-03-12 13:50:42 +03:00
|
|
|
$oldData = $subject->toArray();
|
2024-02-17 11:30:32 +03:00
|
|
|
|
|
|
|
$subject->name = $validated['name'];
|
|
|
|
$subject->description = $validated['description'];
|
|
|
|
$subject->slug = $validated['slug'];
|
|
|
|
$subject->position = $validated['position'];
|
|
|
|
|
2024-03-12 13:50:42 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->warning(
|
|
|
|
'UPDATE предмет {subject} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'subject' => $subject->name,
|
|
|
|
'oldData' => $oldData,
|
|
|
|
'newData' => $validated
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$subject->save();
|
2024-02-17 11:30:32 +03:00
|
|
|
return redirect()->route('subjects.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(Subject $subject): RedirectResponse
|
|
|
|
{
|
|
|
|
if ($subject->entranceExaminations()->exists()) {
|
2024-03-12 13:50:42 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->error(
|
|
|
|
'NOT DELETE предмет {subject} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'subject' => $subject->name,
|
|
|
|
'data' => $subject->toArray(),
|
|
|
|
]
|
|
|
|
);
|
2024-02-17 11:30:32 +03:00
|
|
|
return back();
|
|
|
|
}
|
2024-03-12 13:50:42 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->critical(
|
|
|
|
'DELETE предмет {subject} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'subject' => $subject->name,
|
|
|
|
'data' => $subject->toArray(),
|
|
|
|
]
|
|
|
|
);
|
2024-02-17 11:30:32 +03:00
|
|
|
$subject->delete();
|
|
|
|
return redirect()->route('subjects.index');
|
|
|
|
}
|
|
|
|
}
|