2
on the assumption that all names
the inputs have the same name as the database column.
public function create(){
// o que está abaixo é um exemplo com os dados já populados
$arrayDados= Input::all();
unset($arrayDados["_token"]);
/*$arrayDados = array(
"valor1" => "teste",
"valor2" => "1234",
"valor3"=>1234
);
DB::table("tabela")->insert($arrayDados );*/
DB::table("tabela")->insert($arrayDados );
}
//HTML
<input type="text" name="valor1"/>
<input type="text" name="valor2"/>
<input type="text" name="valor3"/>
//Na tabela do banco de dados
coluna de nome: | valor1 | valor2 | valor3 |
I have 4 forms of ENEM questionnaires (ranging from school subject) with 100 questions each. There are several radios buttons
, textareas
etc. in my view, I find it laborious to bind each of the name's
of html
with the bank column. Is it good practice? Is there any security breach that could happen?
Any reason not to use the Laravel Validator?
– gmsantos
Of course not, I recommend it myself. This function was just an example, in a real project one should use, if it is to use a framework it is to use what it gives us, otherwise it is better not to use
– Miguel
But you are absolutely right to point that out. I edited my answer so that it is '100% Readable'
– Miguel
a small question: do you need to do some treatment to know if the query was successfully saved? for example, if the connection fell in the middle of the transaction, etc. after the
->insert
is it necessary to check something? for example: nopdo
we checked byif ($stmt->execute($data))
– denalioasis
Can create a
try {...} catch(\Illuminate\Database\QueryException $e) { ... erro... }
– Miguel