How can I create a new table in laravel 5.5 with a raw DB string?
$createTableSqlString =
"CREATE TABLE $newTableName (
product_id INT(11) NOT NULL AUTO_INCREMENT,
...
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1;";
I know there is a Illuminate\Support\Facades\Schema for making a new table,
Schema::connection('mysqlInvsys')->create(...);
But how should I define or give it the raw string DB::raw($createTableSqlString)
? I did not find any example in the official doc.
Laravel provides functions for running raw SQL queries as shown here.
For table creation, you can use DB::statement($createTableSqlString)