There’s nothing ready in the Larable for that purpose, but nothing prevents the coding of a Migration with the following code:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class Padrao1 extends Migration
{
public function up()
{
$sql = 'SELECT TABLE_NAME as name FROM information_schema.tables ';
$sql .= 'where TABLE_SCHEMA=? and TABLE_NAME LIKE ? ';
$result = DB::select($sql, [getenv('DB_DATABASE'), 'pesquisas_%']);
foreach($result as $table)
{
Schema::table($table->name, function (Blueprint $table) {
$table->string('code')->after('name');
});
}
}
public function down()
{
}
}
In this code is done a search on the tables of the database configured in the file .env
with the key DB_DATABASE
(getenv('DB_DATABASE')
) with a filter over the prefix tables pesquisas_
, and its return is a list of all tables belonging to this prefix, the rest is equal using Schema::table
, as demonstrated in the code.
References: