request()->input('search'), ]; return Inertia::render('AdminPanel/Student/Index', compact('students', 'filters')); } public function show(Student $student) { $student = new StudentResource($student); return Inertia::render('Client/Student/Show', compact('student')); } public function create() { return Inertia::render('AdminPanel/Student/Create'); } public function store(StoreRequest $request) { $data = $request->validated(); if ($request->file('photo')) { $data['photo'] = $this->storePhoto($request->file('photo')); } Student::create($data); return redirect()->route('admin.student.index'); } public function edit(Student $student) { return Inertia::render('AdminPanel/Student/Edit', compact('student')); } public function update(Student $student, UpdateRequest $request) { $data = $request->validated(); if ($request->file('photo')) { $data['photo'] = $this->storePhoto($request->file('photo')); } $student->update($data); return redirect()->route('admin.student.index'); } public function destroy(Student $student) { $student->delete(); } private function storePhoto(UploadedFile $file) { if ($file->isValid()) { $image = $file; // Генерируем уникальное имя файла, чтобы избежать конфликтов $filename = md5(Carbon::now() . '_' . $image->getClientOriginalName()) . '.' . $image->getClientOriginalExtension(); // Сохраняем изображение в директорию public ImageTool::configure(['driver' => 'imagick']); ImageTool::make($image) ->resize(1200, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }) ->save(storage_path('app/public/photos/' . $filename)); $path = "/storage/photos/" . $filename; // Генерируем URL для доступа к изображению return $path; } } }