public function audit($id)
 {
     $device = Device::findOrFail($id);
     $logs = $device->logs;
     //dd($logs);
     $audit = array();
     $labels = array('name' => 'Identificação', 'serial' => 'Número de Série', 'model' => 'Modelo', 'company_id' => 'Empresa', 'vehicle_id' => 'Veículo', 'description' => 'Observações');
     if ($logs) {
         foreach ($logs as $log) {
             foreach ($log->new_value as $key => $value) {
                 switch ($key) {
                     case 'model':
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? fieldValue("devices", $log->old_value[$key]) : '[novo]', 'new' => fieldValue("devices", $value), 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                     case 'vehicle_id':
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? Vehicle::find($log->old_value[$key])->plate : '[não associado]', 'new' => testVal($log->new_value, $key) ? Vehicle::find($log->new_value[$key])->plate : '[não associado]', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                     case 'company_id':
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? Company::find($log->old_value[$key])->name : '[não associado]', 'new' => testVal($log->new_value, $key) ? Company::find($log->new_value[$key])->name : '[não associado]', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                     default:
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? $log->old_value[$key] : '', 'new' => testVal($log->new_value, $key) ? $log->new_value[$key] : '', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                 }
             }
         }
     }
     $grid = \DataGrid::source($audit);
     $grid->attributes(array("class" => "table table-striped .table-condensed"));
     $grid->add('label', 'Campo');
     $grid->add('old', 'Valor Anterior');
     $grid->add('new', 'Novo Valor');
     $grid->add('user', 'Usuário');
     $grid->add('date', 'Data/Hora');
     $grid->orderBy('date', 'DESC');
     $grid->paginate(10);
     return view('layouts.audit', compact('grid'));
 }