[Solved] "syntax error, unexpected ')'" in vendor/laravel/framework/src/ Illuminate/Testing/Concerns/TestDatabases.php

Laravel Sharif Ahmed

Problem:

While using Laravel 8, you may face an error that says,

"syntax error, unexpected ')'" in vendor/laravel/framework/src/Illuminate/Testing/Concerns/TestDatabases.php

Mainly the error occurs for your PHP version. If you use PHP version lower than 7.3 you may face the error. Here we will discuss some quick solutions for the error.


Solution 1:

To resolve the issue update your PHP version to 7.3 or higher.

    If you are using Valet, execute:

  • valet use php@7.3  // or higher
  • If you are using something like vagrant (and apache):

  • connet to server via "vagrant ssh"
  • install php7.3 or higher (sudo apt install php7.3) and then the related packages that you want
  • disable your current php version via "sudo a2dismod php7.2" (if your current version is 7.2)
  • enable php7.3 via "sudo a2enmod php7.3"
  • restart apache "sudo service apache2 restart"

Solution 2:

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 the second line fixes the issue.


Thank you for reading the article. Hope the solutions will help you to solve your error.