/** * Create a new table * * <code> * // input example * $input = array( * 'posts' => array( * 'title' => array( * 'type' => 'string', * 'length' => 100, * ), * ), * // Can add multiple tables at once * 'post_lang' => array( * 'name' => array( * 'type' => 'string', * ), * 'locale' => array( * 'type' => 'string', * 'length' => 5, * ), * ), * ); * * DBManager::new_table($input); * * </code> * * @param array $input * @return array */ public static function new_table($input) { foreach ($input as $table => $columns) { Schema::create($table, function ($table) use($columns) { if (!isset($columns['id'])) { $table->increments('id'); } foreach ($columns as $name => $data) { if (isset($data['length']) and !is_null($data['length'])) { ${$name} = $table->{$data['type']}($name, $data['length']); } else { ${$name} = $table->{$data['type']}($name); } if (isset($data['nullable']) and $data['nullable'] == true) { ${$name}->nullable(); } } $table->timestamps(); }); } return DBManager::tables(); }