Last active
December 16, 2015 09:28
-
-
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');
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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ü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