diff --git a/app/Http/Controllers/Admin/EducationController.php b/app/Http/Controllers/Admin/EducationController.php index b0d73d3..1b72ae3 100644 --- a/app/Http/Controllers/Admin/EducationController.php +++ b/app/Http/Controllers/Admin/EducationController.php @@ -8,6 +8,7 @@ use App\Http\Requests\ProgramEducationRequest; use App\Models\Education; use App\Models\ProgramEducation; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; class EducationController extends Controller @@ -108,6 +109,22 @@ class EducationController extends Controller return redirect()->route('admin.education.index'); } + public function rename_program(Request $request) { + if ($request->ajax()) { + $oldnamelevel = $request->oldname; + $newnamelevel = $request->newname; + $id_education = $request->id_education; + + $result = DB::table('program_education') + ->where('education_id', '=', $id_education) + ->where('level', '=', $oldnamelevel) + ->update(['level' => $newnamelevel]); + + return $result; + } else return ""; + + } + public function add_program(Request $request) { $id_education = $request->id; $level = $request->level; diff --git a/resources/views/admin/education/form.blade.php b/resources/views/admin/education/form.blade.php index f4f4ba8..10d57da 100644 --- a/resources/views/admin/education/form.blade.php +++ b/resources/views/admin/education/form.blade.php @@ -246,10 +246,21 @@ e.preventDefault(); } - /*if (tabsInput.dataset.edit) { + if (tabsInput.dataset.edit) { tabsBtns.forEach(btn => { if (tabsInput.dataset.edit === btn.dataset.id) { + console.log('oldname: '+btn.textContent+' newname: '+tabsInputValue+' id_education: '+id?>+''); + $.ajax({ + url: '{{ route('admin.rename-program-education') }}', + method: 'get', /* Метод запроса (post или get) */ + dataType: 'html', /* Тип данных в ответе (xml, json, script, html). */ + data: {oldname: btn.textContent, newname:tabsInputValue, id_education: id?>}, /* Данные передаваемые в массиве */ + success: function(data){ /* функция которая будет выполнена после успешного запроса. */ + console.log(data); /* В переменной data содержится ответ от index.php. */ + } + }); + btn.textContent = tabsInputValue; btn.dataset.btn = tabsInputValue; } @@ -261,7 +272,7 @@ if (!tabsBtns.length) { tabsButtons.innerHTML += getTabsBtnTemplate(tabsInputValue, id); - tabsContent.innerHTML += getTabsItemTemplate(id); + //tabsContent.innerHTML += getTabsItemTemplate(id); } if (tabsBtns.length && tabsBtns.length < qty) { @@ -280,7 +291,7 @@ tabsContent.innerHTML += getTabsItemTemplate(id, 'hidden'); } } - }*/ + } //tabsInput.value = ''; addDisabledBtnStatus(tabsSubmitBtn); diff --git a/routes/web.php b/routes/web.php index f3596f9..6d1a073 100644 --- a/routes/web.php +++ b/routes/web.php @@ -226,6 +226,7 @@ Route::group([ // CRUD-операции над справочником Образование Route::resource('education', EducationController::class, ['except' => ['show']]); + Route::get('rename-program-education', [EducationController::class, 'rename_program'])->name('rename-program-education'); Route::get('program-education', [EducationController::class, 'add_program'])->name('add-program-education'); Route::post('program-education', [EducationController::class, 'store_program'])->name('store-program-education');