Nothing is ready in the laravel for this purpose , but nothing prevents the encoding 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 a search is done on the tables of the database configured in the .env
file with the key DB_DATABASE
( getenv('DB_DATABASE')
) with a filter on the tables of the pesquisas_
prefix, and its return is a list of all the tables that belong to this prefix, the rest is equal using Schema::table
, as demonstrated in the code.
References