Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 10, 2020 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/474e67601f78527b0d8e3ff091348564 to your computer and use it in GitHub Desktop.
Save parzibyte/474e67601f78527b0d8e3ff091348564 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Http\Requests\GuardarCambiosDeResponsableRequest;
use App\Http\Requests\GuardarResponsableRequest;
use Illuminate\Support\Facades\Config;
use App\Responsable;
use Illuminate\Http\Request;
class ResponsablesController extends Controller
{
//
public function agregar(GuardarResponsableRequest $peticion)
{
$datosDecodificados = json_decode($peticion->getContent());
$responsable = new Responsable;
$responsable->nombre = $datosDecodificados->nombre;
$responsable->direccion = $datosDecodificados->direccion;
$responsable->areas_id = $datosDecodificados->areas_id;
return response()->json($responsable->save());
}
public function mostrar()
{
return Responsable::orderBy("updated_at", "desc")
->orderBy("created_at", "desc")
->with("area")
->paginate(Config::get("constantes.paginas_en_paginacion"));
}
public function guardarCambios(GuardarCambiosDeResponsableRequest $peticion)
{
$datosDecodificados = json_decode($peticion->getContent());
$idResponsable = $datosDecodificados->id;
$responsable = Responsable::findOrFail($idResponsable);
$responsable->nombre = $datosDecodificados->nombre;
$responsable->direccion = $datosDecodificados->direccion;
$responsable->areas_id = $datosDecodificados->areas_id;
return response()->json($responsable->save());
}
public function buscar(Request $peticion)
{
$busqueda = urldecode($peticion->busqueda);
return Responsable::where("nombre", "like", "%$busqueda%")
->with("area")
->paginate(Config::get("constantes.paginas_en_paginacion"));
}
public function porId(Request $peticion)
{
$idResponsable = $peticion->id;
$responsable = Responsable::where("id", "=", $idResponsable)->with("Area")->first();
return response()->json($responsable);
}
public function eliminar($id)
{
$responsable = Responsable::find($id);
$responsable->delete();
}
public function eliminarMuchos(Request $peticion)
{
$idsParaEliminar = json_decode($peticion->getContent());
return Responsable::destroy($idsParaEliminar);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment