validated(); $faculty = new Faculty(); $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(); 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(); $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(); return redirect()->route('faculties.index'); } public function destroy(Faculty $faculty): RedirectResponse { if ($faculty->departments()->exists()) { return back(); } $faculty->delete(); return redirect()->route('faculties.index'); } }