The code snippet below, receives data from a form, formats and inserts into the database.
This code snippet is located in a controller and the insertion is done in a 'repository' to manipulate data that entity laravel in my project.
Wonder if there are improvements to be made in this code for a great process of receiving, formatting, and data persistence.
- The method HelperRS :: date, gets a date in Brazil and format for timestamp formats.
- The method HelperRS :: real, gets a value in Brazil and format to format float.

// Formats data for inserting budget (orcamento)
$data['idCliente']          = $cliente->id_cliente;
$data['dataIni']            = ($data['dataIni']) ? HelperRS::data($data['dataIni'], 'ts') : NULL;
$data['dataFim']            = ($data['dataFim']) ? HelperRS::data($data['dataFim'], 'ts') : NULL;
$data['elaboradoPor']       = strtoupper(Auth::user()->nome);
$data['loginUsuario']       = Auth::user()->usuario;
$data['dataUltMudanca']     = ($data['dataUltMudanca']) ? HelperRS::data($data['dataUltMudanca'], 'ts') : NULL;
$data['descontoRecibo']     = ($data['descontoRecibo']) ? HelperRS::real($data['descontoRecibo'], 'fl') : NULL;
$data['total']              = ($data['total']) ? HelperRS::real($data['total'], 'fl') : NULL;
$data['totalSemDesconto']   = ($data['totalSemDesconto']) ? HelperRS::real($data['totalSemDesconto'], 'fl') : NULL;
$data['lembrar']            = ($data['lembrar']) ? HelperRS::data($data['lembrar'], 'ts') : NULL;;
$id_orcamento = $this->orcamentos->insert($data);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.