Skip to content

Instantly share code, notes, and snippets.

@peponi
Last active December 16, 2015 09:28
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 peponi/5412874 to your computer and use it in GitHub Desktop.
Save peponi/5412874 to your computer and use it in GitHub Desktop.
a short snippet to map laravel form response to DB insert array <?php echo Form::input('text','alter') ?> input attr title needs to be the same like the db table row titles -> $table->integer('alter');
<?php
public function post_some_crap()
{
$result = Input::get();
/* ============= just a smal data maper snippit ================= */
// replace the table name in ::query('show columns from <tablename> ');
// got all rows as index from table
$data_array = DB::query('show columns from formsheet2');
// delete the id row 'cause there is now id index in the $result array
unset($data_array[0]);
$array_map = [];
foreach ($data_array as $key => $data)
{
if( array_key_exists($data->field, $result) )
{
$array_map[ $data->field ] = $result[ $data->field ];
}
else
{
echo "Der Index '".$data->field."' ist nicht im R&uuml;ckgabewert des Formulars vorhanden.";
exit;
}
}
/* =============================================================== */
DB::table('formsheet2')->insert( $array_map );
return Redirect::to_action('home@show_all_formsheets');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment