diff --git a/app/Area.php b/app/Area.php index 7d4e550..2218af0 100644 --- a/app/Area.php +++ b/app/Area.php @@ -13,4 +13,8 @@ class Area extends Model public function detalleEncuestas(){ return $this->hasMany("App\Detalle_encuesta"); } + + public function areaEn(){ + return $this->hasOne('App\Area_en', 'id' , 'id'); + } } diff --git a/app/Http/Controllers/AreasController.php b/app/Http/Controllers/AreasController.php new file mode 100644 index 0000000..f515ba2 --- /dev/null +++ b/app/Http/Controllers/AreasController.php @@ -0,0 +1,90 @@ +forget('delete_failed'); + } + return view('areas.list')->with('dbData', $dbData)->with('toast', $toast); + } + + public function create(){ + return view('areas.create'); + } + + public function store(Request $request){ + DB::transaction(function() use($request){ + //Cargamos el área en español + $dbData = new Area($request->all()); + //Cargamos el área en inglés + $dbDataEn = new Area_en(); + $dbDataEn->descripcion = $request->descripcion_en; + //Guardamos los registros + $dbData->save(); + $dbDataEn->save(); + }); + + return redirect()->route('areas.index'); + } + + public function show($id) + { + // + } + + public function edit($id){ + $dbData = Area::find($id); + return view('areas.edit')->with('dbData', $dbData); + } + + public function update(Request $request, $id){ + + //Area en español + $dbData = Area::find($id); + //Area en inglés + $dbDataEn = Area_en::find($id); + DB::transaction(function() use($request, $id, $dbData, $dbDataEn){ + //Cargamos el área en español + $dbData->fill($request->all()); + //Cargamos el área en inglés + $dbDataEn->descripcion = $request->descripcion_en; + //Guardamos los registos + $dbData->save(); + $dbDataEn->save(); + }); + + + + return redirect()->route('areas.index'); + } + + public function destroy($id){ + DB::beginTransaction(); + try{ + $dbData = Area::find($id); + $dbDataEn = Area_en::find($id); + $dbData->delete(); + $dbDataEn->delete(); + }catch(\Exception $e){ + DB::rollback(); + session(['delete_failed'=>"true"]); + return redirect()->back()->withErrors($e->getMessage()); + } + DB::commit(); + + return redirect()->route('areas.index'); + } +} diff --git a/app/Http/Controllers/FileAttachmentController.php b/app/Http/Controllers/FileAttachmentController.php index ceb5805..d7b7fd4 100644 --- a/app/Http/Controllers/FileAttachmentController.php +++ b/app/Http/Controllers/FileAttachmentController.php @@ -121,7 +121,7 @@ public function upload(Request $request){ public function getPeriodosAjax(Request $request){ $periodos = $this->getPeriodos($request->rubro_id); - + session(['delete_failed'=>"true"]); return $periodos; } diff --git a/app/Http/Controllers/NivelesController.php b/app/Http/Controllers/NivelesController.php new file mode 100644 index 0000000..72de1dd --- /dev/null +++ b/app/Http/Controllers/NivelesController.php @@ -0,0 +1,87 @@ +forget('delete_failed'); + } + return view('niveles.list')->with('dbData', $dbData)->with('toast', $toast); + } + + public function create(){ + return view('niveles.create'); + } + + public function store(Request $request){ + DB::transaction(function() use($request){ + //Cargamos el área en español + $dbData = new Nivel($request->all()); + //Cargamos el área en inglés + $dbDataEn = new Nivel_en(); + $dbDataEn->descripcion = $request->descripcion_en; + //Guardamos los registros + $dbData->save(); + $dbDataEn->save(); + }); + + return redirect()->route('niveles.index'); + } + + public function show($id) + { + // + } + + public function edit($id){ + $dbData = nivel::find($id); + return view('niveles.edit')->with('dbData', $dbData); + } + + public function update(Request $request, $id){ + + //nivel en español + $dbData = Nivel::find($id); + //nivel en inglés + $dbDataEn = Nivel_en::find($id); + DB::transaction(function() use($request, $id, $dbData, $dbDataEn){ + //Cargamos el área en español + $dbData->fill($request->all()); + //Cargamos el área en inglés + $dbDataEn->descripcion = $request->descripcion_en; + //Guardamos los registos + $dbData->save(); + $dbDataEn->save(); + }); + return redirect()->route('niveles.index'); + } + + public function destroy($id){ + DB::beginTransaction(); + try{ + $dbData = Nivel::find($id); + $dbDataEn = Nivel_en::find($id); + $dbData->delete(); + $dbDataEn->delete(); + + }catch(\Exception $e){ + DB::rollback(); + session(['delete_failed'=>"true"]); + return redirect()->back()->withErrors($e->getMessage()); + } + DB::commit(); + return redirect()->route('niveles.index'); + } +} diff --git a/app/Nivel.php b/app/Nivel.php index 4b72baa..071a70e 100644 --- a/app/Nivel.php +++ b/app/Nivel.php @@ -13,4 +13,8 @@ class Nivel extends Model public function detalleEncuestas(){ return $this->hasMany("App\Detalle_encuesta"); } + + public function nivelEn(){ + return $this->hasOne('App\Nivel_en', 'id' , 'id'); + } } diff --git a/resources/views/areas/create.blade.php b/resources/views/areas/create.blade.php new file mode 100644 index 0000000..3d949e8 --- /dev/null +++ b/resources/views/areas/create.blade.php @@ -0,0 +1,30 @@ +@extends('layout') +@section('content') +
Id | +Descripción | +Descripción (Inglés) | +Opciones | +
---|---|---|---|
{{ $est->id }} | +{{ $est->descripcion }} | +{{ $est->areaEn->descripcion }} | ++ editEditar + + + + deleteBorrar + + + | +