Skip to content

Commit f11c0cd

Browse files
committed
Updated creation of tables. Validation in Controller, column:type
1 parent c673680 commit f11c0cd

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

app/Http/Controllers/Controller.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,25 @@ public function t_store(Request $request)
4141
return abort(400, "No tablename given.");
4242

4343
$tableName = $request->tablename;
44-
$table = $request->input();
44+
45+
$table = array();
46+
$table['id'] = "increments";
47+
48+
foreach ($request->input() as $column => $type) {
49+
if ($column != "id" && $column != "tablename") // Don´t use these
50+
if ($type=="text" || $type=="integer") // Enabled types
51+
$table[$column] = $type;
52+
}
4553

4654
if (!TableController::table_store($tableName,$table))
4755
return abort(500, "Failed to create Table '$tableName'");
48-
56+
4957
// Summary of the created table
5058
echo "<pre>";
5159
echo "CREATE TABLE '$tableName'\n";
5260
echo "(\n";
53-
echo " 'id' integer not null primary key autoincrement\n";
54-
foreach ($table as $key => $value) {
55-
if ($key != "id" && $key != "tablename")
56-
echo " '$key' $value\n";
61+
foreach ($table as $column => $type) {
62+
echo " '$column' $type\n";
5763
}
5864
echo ")</pre>";
5965

app/Http/Controllers/TableController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ public static function table_store($tableName,$table)
6060
return false;
6161

6262
Schema::create($tableName, function($t) use ($table){
63-
$t->increments('id');
64-
6563
foreach ($table as $key => $value){
66-
if ($key != "id" && $key != "tablename")
67-
$t->$value($key);
64+
$t->$value($key);
6865
}
6966
});
7067

0 commit comments

Comments
 (0)