Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current none :
/
var
/
www
/
html
/
tpid-jsd
/
app
/
Http
/
Controllers
/
Section
/
Or
Select Your none :
Upload File :
New :
File
Dir
/var/www/html/tpid-jsd/app/Http/Controllers/Section/AgendaController.php
<?php namespace App\Http\Controllers\Section; use App\Http\Controllers\Controller; use App\Models\Agenda; use App\Models\DetailAgenda; use App\Models\Language; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Exception; class AgendaController extends Controller { public function index() { $languages = Language::get(); $agendas = Agenda::with('details')->get()->groupBy('language_id'); return view('section.agenda.index', compact('agendas', 'languages')); } public function update(Request $request) { try { DB::beginTransaction(); $post = $request->except('_token'); DB::table('agendas')->delete(); foreach ($post as $key => $agendas) { foreach ($agendas as $agenda) { $update_agenda = Agenda::updateOrCreate([ "id" => $agenda['agenda_id'], ] , [ "language_id" => $key, "name" => $agenda['name'], "date" => $agenda['date'] ?? null, ]); foreach ($agenda['detail'] ?? [] as $detail) { $update_detail = DetailAgenda::updateOrCreate([ "id" => $detail['detail_id'], ] , [ "agenda_id" => $update_agenda['id'], "hours" => $detail['hours'] ?? null, "name" => $detail['title'] ?? null, "description" => $detail['description'] ?? null, ]); } } } DB::commit(); return redirect()->back()->withSuccess('Agenda has been updated'); } catch (Exception $err) { DB::rollBack(); return redirect()->route('agenda.index')->withErrors([$err->getMessage()]); } } }