1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public function createTable($table_name, $fields = [])
{
// check if table is not already exists
if (!Schema::hasTable($table_name)) {
Schema::create($table_name, function (Blueprint $table) use ($fields, $table_name) {
$table->increments('id');
if (count($fields) > 0) {
foreach ($fields as $field) {
$table->{$field['type']}($field['name']);
}
}
$table->timestamps();
});
return response()->json(['message' => 'Given table has been successfully created!'], 200);
}
return response()->json(['message' => 'Given table is already existis.'], 400);
} |