Description
Laravel Version
12.0.1
PHP Version
8.3
Database Driver & Version
MySQL
Description
When running php artisan migrate:fresh in Laravel 12, the migration process fails if the database name contains a dot (.). This happens because Laravel splits table names on the dot character when compiling the DROP TABLE statement, leading to an invalid SQL query.
Cause
The issue originates from Illuminate\Database\Grammar.php, where table names are split on . using explode(), assuming it’s a schema/table separator. However, this does not account for databases with dots in their names.
Relevant Code
public function compileDropAllTables($tables)
{
return 'drop table '.implode(',', $this->wrapArray($tables));
}
public function wrapArray(array $values)
{
return array_map($this->wrap(...), $values);
}
public function wrap($value)
{
return $this->wrapSegments(explode('.', $value));
}
Expected Behavior
Laravel should correctly wrap the full database name and table name without splitting on dots inside database names.
Database Driver & Version: [e.g., MySQL 8.0]
Would appreciate any guidance on how to resolve this!
Steps To Reproduce
Set up a database with a name containing a dot, e.g., website.com.
Configure .env with this database name:
DB_DATABASE=website.com
Run:
php artisan migrate:fresh
Laravel generates an invalid SQL query:
drop table
website.
com.
cache``
Instead of:
drop table
website.com.
cache``