Ver Mensaje Individual
  #9 (permalink)  
Antiguo 14/09/2017, 11:09
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: Como obtener atributos originales y los atributos actualizados

hhs en el modelo estaciones tengo

Código PHP:
Ver original
  1. //Crear
  2. Estacion::created(function(Estacion $estacion) {
  3.  
  4. });
  5.  
  6. //Actualiza
  7. Estacion::saving(function(Estacion $estacion){
  8. $dirty = $estacion->getDirty();
  9.         foreach ($dirty as $field => $newdata)
  10.         {
  11.           $olddata = $estacion->getOriginal($field);
  12.           if ($olddata != $newdata)
  13.           {
  14.             if($estacion->id){
  15.                 $historial = new Historial();
  16.                 $historial->viejo =$field.'='.$olddata;
  17.                 $historial->nuevo =$field.'='.$newdata;
  18.                 $historial->estacion_id=$estacion->id;
  19.                 $historial->autor_id = Auth::user()->id;
  20.                 $historial->save();            
  21.             }
  22.  
  23.           }
  24.         }
  25.  
  26.      });


El requerimiento que tengo es mostrar los cambios que se han presentado en cada una de las estaciones para este fin tengo la tabla historial_estaciones y la mapeo con el modelo Historial
Código SQL:
Ver original
  1. CREATE TABLE historial_estaciones
  2. (
  3.   id serial NOT NULL,
  4.   viejo text,
  5.   nuevo text,
  6.   estacion_id INTEGER,
  7.   autor_id INTEGER,
  8.   created_at TIMESTAMP WITHOUT TIME zone NOT NULL,
  9.   updated_at TIMESTAMP WITHOUT TIME zone NOT NULL,
  10.   CONSTRAINT historial_estaciones_pkey PRIMARY KEY (id)
  11. )
  12. WITH (
  13.   OIDS=FALSE
  14. );
  15. ALTER TABLE historial_estaciones
  16.   OWNER TO postgres;

en la vista muestro así:
Código HTML:
Ver original
  1. Nuevo                         Antiguo
  2. nombre=prueba1  nombre=prueba2
  3. latitud_wgs84=4.31  latitud_wgs84=4.3


en la vista necesito mostrar la informacion así

Nuevo Antiguo
Nombre=prueba1 Nombre=prueba2
Latitud=4.31 Latitud=4.3




también tendría otro historial que para todo el sistema y los diferentes modelos donde indique cuando crea o actualizo.

Última edición por Montes28; 14/09/2017 a las 11:16