I am Getting error when I open the laravel 8 project
protected function switchToDatabase($database)
{
DB::purge();
$default = config('database.default');
config()->set(
"database.connections.{$default}.database",
$database,
);
}
"syntax error, unexpected ')'" in vendor/laravel/framework/src/Illuminate/Testing/Concerns/TestDatabases.php
Gert B. answer does solve the situation, but you should instead update your PHP to version 7.3 or higher, as Mohammad mentioned, to solve this. Changing platform/vendor code is not the best option.
You're using a PHP version lower than 7.3
in: vendor/laravel/framework/src/Illuminate/Testing/Concerns/TestDatabases.php
Change:
if ($url) {
config()->set(
"database.connections.{$default}.url",
preg_replace('/^(.*)(\/[\w-]*)(\??.*)$/', "$1/{$database}$3", $url),
);
} else {
config()->set(
"database.connections.{$default}.database",
$database,
);
}
to:
if ($url) {
config()->set(
"database.connections.{$default}.url",
preg_replace('/^(.*)(\/[\w-]*)(\??.*)$/', "$1/{$database}$3", $url)
);
} else {
config()->set(
"database.connections.{$default}.database",
$database
);
}
Removing the comma at the end of line fixes the issue.
remove the trailing "," in your set function call:
config()->set(
"database.connections.{$default}.database",
$database
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With